kneifelspy Posted January 14, 2009 Share Posted January 14, 2009 For SOME reason, when I upload an image file to my database table using my form, when it uploads to the database it is corrupt. From what I can tell, the image isn't fully uploaded. For instance, a GIF that is 16kb will be uploaded and only 12kb of data will be there. I am using phpMyAdmin and the image is going into a LONG_BLOB. I've tried changing the BLOB type, and nothing helps. Every image uploaded is corrupt. However, when I upload the image IN phpMyAdmin, the file is fine. Here is my upload script: mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.'); mysql_select_db($dbname); $filename = $_FILES['cf_photo']['name']; $filetype = $_FILES['cf_photo']['type']; $filesize = $_FILES['cf_photo']['size']; $tmp_filename = $_FILES['cf_photo']['tmp_name']; $fp = fopen($tmp_filename, 'r'); $filedata = fread($fp, filesize($tmp_filename)); $filedata = mysql_real_escape_string(stripslashes($filedata)); fclose($fp); $cf_band = mysql_real_escape_string(stripslashes($_POST['cf_band'])); $cf_title = mysql_real_escape_string(stripslashes($_POST['cf_title'])); $cf_body = mysql_real_escape_string(stripslashes($_POST['cf_body'])); $cf_web = mysql_real_escape_string(stripslashes($_POST['cf_web'])); $cf_author = mysql_real_escape_string(stripslashes($_POST['cf_author'])); $cf_timestamp = mysql_real_escape_string(stripslashes($_POST['cf_timestamp'])); $query="INSERT INTO reviews VALUES ('','$cf_band', '$cf_title', '$filedata', '$filename', '$filetype', '$cf_body', '$cf_web', '$cf_author', '$cf_timestamp')"; mysql_query($query); echo '<b>Post Successfully Added!</b><br /><br />'; mysql_close(); Anyone have any idea what's going on? These files are TOO SMALL to be having issues due to size. Quote Link to comment https://forums.phpfreaks.com/topic/140772-solved-database-image-too-small-after-upload/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 14, 2009 Share Posted January 14, 2009 $filedata = mysql_real_escape_string(stripslashes($filedata)); You should only use stripslashes() if escape characters were added by the magic_quotes (either _gpc or _runtime depending on how the data is being processed and note $_FILES data is not affected by magic_quotes_gpc) settings. Unconditionally stripping slashes from an image will remove \ characters that are part of the data. Since you are using file functions to read the file, you should turn magic_quotes_runtime off either in a php.ini file, in a .htaccess file (when available), or in your script. Quote Link to comment https://forums.phpfreaks.com/topic/140772-solved-database-image-too-small-after-upload/#findComment-736816 Share on other sites More sharing options...
kneifelspy Posted January 14, 2009 Author Share Posted January 14, 2009 That was it. I was stripping characters from the data while trying to manage magic_quotes. I will turn off magic_quotes on my server and fix my code all around. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/140772-solved-database-image-too-small-after-upload/#findComment-736819 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.