Upload related question functions.

Source: Internet
Author: User
For the upload question function, please [code = PHP] [/code] & lt ;? Phpheader (& quot; content-Type: text/html; charset = gb2312 & quot;); $ uptypes = array ('image/jpg ', // the function for uploading File uploads
[Code = PHP] [/code]
Header ("content-Type: text/html; charset = gb2312 ");
$ Uptypes = array ('image/jpg ', // list of uploaded File types
'Image/jpeg ',
'Image/png ',
'Image/pjpeg ',
'Image/GIF ',
'Image/bmp ',
'Application/x-shockwave-Flash ',
'Image/x-png ',
'Application/msword ',
'Audio/x-ms-wm ',
'Audio/MP3 ',
'Application/vnd. rn-realmedia ',
'Application/x-zip-compressed ',
'Application/octet-stream ');

$ Max_file_size = 20000000; // size limit of uploaded files, in bytes
$ Path_parts = pathinfo ($ _ SERVER ['php _ SELF ']); // Obtain the current path
$ Destination_folder = "up/"; // file Upload path
$ Imgpreview = 1; // whether to generate a preview image (1 is generated, others are not generated );
$ Imgpreviewsize = 1/2; // Thumbnail ratio


$ File = & $ HTTP_POST_FILES ['userfile'];
// Var_dump ($ file );
If ($ max_file_size <$ file ["size"])
// Check the file size
{
Echo "the file is too large! ";
Exit;
}

If (! In_array ($ file ["type"], $ uptypes ))
// Check the file type
{
Echo "cannot upload this type of files! ";
Exit;
}
// Check whether the upload directory exists. if not, create
If (! File_exists ($ destination_folder )){
Mkdir ($ destination_folder );
}
$ Filename = $ file ["tmp_name"];
$ Image_size = getimagesize ($ filename );
$ Pinfo = pathinfo ($ file ["name"]);
$ Ftype = $ pinfo [extension];
$ Destination = $ destination_folder.time (). ".". $ ftype;
$ Fname = time (). ".". $ ftype;
If (file_exists ($ destination) & $ overwrite! = True)
{
Echo "the file with the same name already exists! ";
Exit;
}

If (! Move_uploaded_file ($ filename, $ destination ))
{
Echo "an error occurred while moving the file! ";
Exit;
} Else {
// Add the part written to the database
// Create a database connection
$ Con = mysql_connect ('localhost', 'root', '000000') or die ('could not connect: '. mysql_error ());
// Echo 'connectedsuccessfully ';
$ Db = mysql_select_db ('download', $ con );
Mysql_query ("set names gb2312 ");
If (! $ Db ){
Die ("Can \'t use download:". mysql_error ());
} Else {
// Insert user information into the user table of the database
$ SQL = "INSERT INTO 'register '. 'scb' ('id', 'Fl ', 'zuoz', 'filename', 'Des ', 'fsize', 'ftype', 'utime') VALUES (NULL, '". $ fl. "','". $ zuo. "',". $ fname. "','','". $ file ["size"]. "','". $ file ["type"]. "', NOW ());";
$ Result = mysql_query ($ SQL );
If (! $ Result ){
// Release the result set
Mysql_free_result ($ result );
// Close the connection
Mysql_close ($ db );
Echo 'data record insertion failed! ';
Exit;
}
}
}
$ Pinfo = pathinfo ($ destination );
$ Fname = $ pinfo [basename];
Echo"
File upload address: http: // ". $ _ SERVER ['server _ name']. $ path_parts [" dirname "]."/". $ destination_folder. $ fname ."
";
Echo "width:". $ image_size [0];
Echo "length:". $ image_size [1];
If ($ watermark = 1)
{
$ Iinfo = getimagesize ($ destination, $ iinfo );
$ Nimage = imagecreatetruecolor ($ image_size [0], $ image_size [1]);
$ White = imagecolorallocate ($ nimage, 255,255,255 );
$ Black = imagecolorallocate ($ nimage, 0, 0 );
$ Red = imagecolorallocate ($ nimage, 255, 0, 0 );
Imagefill ($ nimage, 0, 0, $ white );
Switch ($ iinfo [2])
{
Case 1:
$ Simage = imagecreatefromgif ($ destination );
Break;
Case 2:
$ Simage = imagecreatefromjpeg ($ destination );
Break;
Case 3:
$ Simage = imagecreatefrompng ($ destination );
Break;
Case 6:
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.