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"