Php uploads image code (saves images to the database at the same time) _ PHP Tutorial

Source: Internet
Author: User
Tags mysql tutorial
Upload the image code in php (save the image to the database at the same time ). Php uploads image code (saving images to the database at the same time) * The php Upload image code provided below is a use of phpcopy to upload files. it not only uploads images to the server, php uploads the image code (saving images to the database at the same time)/* The php Upload image code provided below is a use of php copy to upload files. it not only uploads images to the server, at the same time, the image address is saved to the mysql database.

Php Tutorial Upload image code (saving images to the database at the same time)
/*
The following php image upload code uses php copy to upload files. it not only uploads images to the server, at the same time, save the image address to the mysql tutorial database.
*/

// Connect to the database
$ Conn = mysql_connect ("localhost", "phpdb", "phpdb ");
Mysql_select_db ("test", $ conn );
?>
// Obtain the webpage parameters
$ Id = $ _ post ['id'];

// Determine whether the user name already exists
$ Checksql = "select * from image where id = '$ ID '";
$ Check_re = mysql_query ($ checksql, $ conn );
$ Num = mysql_num_rows ($ check_re );
If ($ num! = 0 ){
Echo"

";
Echo "this user name already exists. please select another one
";
Echo "Upload failed!
Return ";
Echo"
";
Exit ();
}

// Method 2: save only the file name,
// When saving the file name, the file is in the temporary upload directory set in the php. ini configuration file, that is, the upload_tmp_dir parameter.

If ($ photo <> ""){
If ($ photo_type = "image/pjpeg") or ($ photo_type = "image/gif ")){
// C: temporary directory of the upload file set in the php. ini configuration file in winnttemp
$ Photodir = "c: winnttemp /";
If (! (File_exists ($ photo_name ))){
// Copy the image file to the temporary directory of the specified Upload file
Copy ($ photo, $ photodir. $ photo_name );
}
}
Else {
Echo"

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.