Modify Upload image? & Lt; tr & gt; & nbsp; & lt; tdwidth & quot; 15% & quot; & gt; select the image address: & lt; td & gt; & nbsp; & lt; tdwidth & quot; 85% & quot; & gt; & lt; inputtype & quot; file & quot; name & quot; myphoto & quot; & g modify the upload image?
Select Image address:
I can upload images and modify them. The problem is that the images are stored in the database in the form of binary stream blob, so I don't know how to read this address, the image address in the database remains unchanged when the image name is modified and the address is not modified.
------ Solution --------------------
Convert image to binary
$ Img_file = 'xxx.jpg ';
$ Fp = fopen ($ img_file, 'RB ');
$ Content = fread ($ fp, filesize ($ img_file); // binary data
Fclose ($ fp );
Query display:
Header ("content-type: image/jpeg ");
List ($ st1, $ st2) = explode ("", microtime ());
$ StartTime = $ st1 + $ st2;
// $ PicContent = file_get_contents ("1.jpg ");
$ Lnk = mysql_connect ("localhost", "root", "123456 ");
Mysql_select_db ("test ");
// $ PicContents = base64_encode ($ picContent );
// $ Re = mysql_query ("insert into pic values (NULL, '$ picContents ')");
$ Re = mysql_query ("select * from pic ");
! $ Re & die ("query failed !~ ");
$ Rs = mysql_fetch_array ($ re );
Mysql_close ($ lnk );
Echo base64_decode ($ rs ['Pic ']);
List ($ st1, $ st2) = explode ("", microtime ());
$ Time2 = $ st1 + $ st2;
Echo 'execution Time'. ($ time2-$ startTime );
?>
Suggestion: encode binary data with base64 before joining the database. otherwise, some special symbols may cause insertion failure.
------ Solution --------------------
Upload processing:
// Because the uploaded image is saved in a temporary file
// You only need to read the file to obtain the uploaded image.
$ Fp = fopen ($ _ FILES ["myFile"] ["tmp_name"], "rb ");
$ Buf = addslashes (fread ($ fp, $ _ FILES ["myFile"] ["size"]);
// Create a PDO object
$ Dbh = new PDO ("mysql: host = localhost; port =
3306; dbname = myDatabase "," root "," verysecret ");
// Execute the insert operation and save the result in a variable
$ Result = $ dbh-> query ("insert into employees
(FirstName, lastName, EmpType, age, picture) VALUES
('Myfirst', 'myla', 'myemptype ', 50,' $ buf ')");
// Obtain the number of affected rows
If ($ result-> rowCount ()> 0 ){
Echo ("data inserted. ");
} Else {
Echo ("The INSERT operation cannot be performed. ");
}
// Explicitly close the PDO connection
$ Dbh = NULL;
?>
------ Solution --------------------
If a database exists, you can modify the text as usual...
It can be a string.
------ Solution --------------------
Header ("content-type: image/jpeg"); add