Forum Moderators: coopster
Iam developing an appication regarding storing of images in mysql database in binary format. During reading iam getting the following error.
$fileHandle = fopen($fileUpload, "rb");
$fileContent = fread($fileHandle, filesize($fileUpload));
$fileContent = addslashes($fileContent);
The following is the error iam getting
fread(): supplied argument is not a valid stream resource in /var/www/grabfile.php on line 5
Some body please help me.
THanks
i got it the correct code follows like this
//Declaration of global variables
global $strDesc;
global $fileUpload_name;
global $fileUpload_tmpname;
global $fileUpload_size;
global $fileUpload_type;
global $file_ff;
global $file_fw;
global $file_tumor;
$strDesc = $HTTP_POST_VARS["strDesc"];
//print_r($_FILES);
$fileUpload_name = $_FILES['fileUpload']['name'] . "<br>";
$fileUpload_tmpname = $_FILES['fileUpload']['tmp_name'] . "<br>";
$fileUpload_size = $_FILES['fileUpload']['size'] . "<br>";
$fileUpload_type = $_FILES['fileUpload']['type'] . "<br>";
and the fread and fopen statements are corrected as following
$fileHandle = fopen($_FILES['fileUpload']['tmp_name'], "rb");
$fileContent = fread($fileHandle, $_FILES['fileUpload']['size']);
$fileContent = addslashes($fileContent);
THanks
I was wondering though, I don't know your app but have you considered uploading the files to a writeable directory and just putting the path to the file in the MySQL? It keeps the MySQL meaner, trimmer, faster, and makes automated data backups a heck of a lot easier later especially if you have scads of pictures.
Just wondering,
Burner
remember when allowing people to upload anything to your site that you make absolutely sure what it is they're sending and only allow the proper files.
It would be unfortunate for them to upload an executable or soemthing else nasty and to have it viewable to them or to put it into your db.
I was actually debating with myself over whether I should have brought up some of the moral/ethical debates here. (Not your morals/ethics Shamboo) Some ISPs will absolutely not tolerate anything but text if you use a shared MySQL plan and consider it bad form. Additionally there's almost always eventually someone who tries uploading things you wouldn't expect, just to see what happens. The larger the site, the more likely someone will try to damage you.
If you backup your MySQL database through some type of browser script, you could be waiting hours to complete. Graphic files get HUGE when you're storing them. Better to leave 'em on a hard drive IMHO.
Burner