Hi people, Now before you say that it is a bad idea. I want to figure out a something before I ever trying to do such a thing for something serious. I was arguing with my colleague about the matter. He's quite an old guy with a lot of php/MySQL experience. So he is on the side of storing the files and especially pictures in MySQL database. I myself just store the reference to the file saving on database size and speed. His main point is that the path to the file can get lost and in the result all you will have is a blank web-page on the output. He gave me a piece of used up code for accomplishing this. Can be found at http://www.techcubetalk.com/2009/01/tutorial-on-how-to-store-images-in-mysql-blob-field/ and come other places. Same thing everywhere. But this thing is as broken as it can be and the output is not an error or any other message but the half of the code on the main page. Something like this
0) { $fileName = $_FILES['imgfile']['name']; // image file name $tmpName = $_FILES['imgfile']['tmp_name'];
// name of the temporary stored file name $fileSize = $_FILES['imgfile']['size']; // size of the uploaded file
$fileType = $_FILES['imgfile']['type']; // file type $fp = fopen($tmpName, 'r'); // open a file handle of the
temporary file $imgContent = addslashes(fread($fp, filesize($tmpName))); // read the temp file // $imgContent =
fread($fp, filesize($tmpName)); // read the temp file fclose($fp); // close the file handle $query = "INSERT INTO
img_up (`name`, `type`, `size`, `content` ) VALUES (’$fileName’, ‘$fileType’, ‘$fileSize’, ‘$imgContent’)";
mysql_query($query) or die('Error, query failed'); $imgid = mysql_insert_id(); // autoincrement id of the uploaded entry mysql_close($dbconn); echo "
Image successfully uploaded to database
"; echo "View Image"; }else die("You have not selected any image"); ?>
When he showed me one of the databases I've seen all the blobs filled with data. And it works all the time. But he refuses to show how and what he's done. Only a hint that he changed a few parts of that thing. How does he do that?