awebbdesigner Posted September 25, 2010 Share Posted September 25, 2010 Hi All, Having issues uploading files larger than 1mb. This is what I have currently as default when I ran phpinfo() (working locally on my machine)... upload_max_filesize: 432M post_max_size: 432M memory_limit: 8M max_input_time: 60 max_execution_time: 30 I'm looking for the file to be converted into a blob, it works perfectly fine for files less than 1mb, but doesn't even run the mysql query above that. Any Ideas anyone? include("../../connect.php"); # these settings should help set_time_limit(0); # going in as a blob from now on $stamp = mktime(); $safename = $_FILES['Filedata']['tmp_name']; $filename = $_FILES['Filedata']['name']; $size = $_FILES['Filedata']['size']; $type = $_FILES['Filedata']['type']; $fk = $_REQUEST['fk']; $sqlname = $stamp . "-" . $_FILES['Filedata']['name']; # open and code in $fp = fopen($safename, 'r'); $content = fread($fp, filesize($safename)); $content = addslashes($content); fclose($fp); $insertS = "INSERT INTO $tableb (pal, afield, bfield, cfield, dfield, efield, ffield, ablob) VALUES ('6', '$fk', '$filename', '$size', '$type', '$width', '$height', '$content')"; $insertQ = mysql_query($insertS); print "1"; Quote Link to comment https://forums.phpfreaks.com/topic/214363-large-upload-into-blob/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 25, 2010 Share Posted September 25, 2010 echo mysql_error(); on the next line after the line with your msyql_query() statement to see if there are any query errors. There is a maximum packet size for any query that you are likely exceeding (all the more reason to NOT store files in a database.) Quote Link to comment https://forums.phpfreaks.com/topic/214363-large-upload-into-blob/#findComment-1115533 Share on other sites More sharing options...
awebbdesigner Posted September 25, 2010 Author Share Posted September 25, 2010 I should of mentioned that I am making this request using ajax (Jquery Uploadify) so its hard for me to see the error, I will try a separate query though. Quote Link to comment https://forums.phpfreaks.com/topic/214363-large-upload-into-blob/#findComment-1115534 Share on other sites More sharing options...
PFMaBiSmAd Posted September 25, 2010 Share Posted September 25, 2010 You can always use the error_log function to write information from your script to an error log file of your choice. Edit: If you are using ajax for this, you should also be using ajax to display any status/error information that your php code sends out to the browser. Quote Link to comment https://forums.phpfreaks.com/topic/214363-large-upload-into-blob/#findComment-1115536 Share on other sites More sharing options...
awebbdesigner Posted September 25, 2010 Author Share Posted September 25, 2010 I will endeavor to get more error messages shortly as I am not familiar with error_log $insertS = "INSERT INTO $tableb (pal, afield, bfield, cfield, dfield, efield, ffield, ablob) VALUES ('6', '$fk', '$filename', '$size', '$type', '$width', '$height', '$content')"; $insertQ = mysql_query($insertS); I have added... $errQ = mysql_query("INSERT INTO $tableb (pal, atext) VALUES ('1', '" . mysql_error($insertQ) . "')"); However the text field is blank, have I written it correctly? Quote Link to comment https://forums.phpfreaks.com/topic/214363-large-upload-into-blob/#findComment-1115541 Share on other sites More sharing options...
awebbdesigner Posted September 25, 2010 Author Share Posted September 25, 2010 I still can't get any further information, you mentioned packet size whichI googled, couldn't make heads or tails of it, is there anyway of changing it from 1mb to say 10mb during runtime? if so can you write an example? Quote Link to comment https://forums.phpfreaks.com/topic/214363-large-upload-into-blob/#findComment-1115552 Share on other sites More sharing options...
PFMaBiSmAd Posted September 25, 2010 Share Posted September 25, 2010 but doesn't even run the mysql query above that. ^^^ What makes you think that? Quote Link to comment https://forums.phpfreaks.com/topic/214363-large-upload-into-blob/#findComment-1115555 Share on other sites More sharing options...
awebbdesigner Posted September 25, 2010 Author Share Posted September 25, 2010 When I upload an image 1mb or less, I can see the row in the table (name, description, blob image). However when I try to upload and image above 1mb there is now row added in the table, not even the description. Its like it doesn't like an image over 1mb and then just fails. Hope this is clear. Quote Link to comment https://forums.phpfreaks.com/topic/214363-large-upload-into-blob/#findComment-1115557 Share on other sites More sharing options...
chintansshah Posted September 25, 2010 Share Posted September 25, 2010 I think, you should echo your insert query string and run on PHPMyadmin, if it executes successfully then you have to debug your php code. I reviewed your code, but you haven't apply filter on $_REQUEST value using htmlentities, addslashes, mysql_real_escape_string etc..etc... Quote Link to comment https://forums.phpfreaks.com/topic/214363-large-upload-into-blob/#findComment-1115559 Share on other sites More sharing options...
PFMaBiSmAd Posted September 25, 2010 Share Posted September 25, 2010 mysql_error($insertQ) ^^^ That's invalid. mysql_error() does NOT use a result resource as a parameter and that code would have been producing a php error, assuming you are doing this on a system with error_reporting set to E_ALL and display_errors and/or log_errors ON so that php errors would be reported and displayed/logged. Quote Link to comment https://forums.phpfreaks.com/topic/214363-large-upload-into-blob/#findComment-1115562 Share on other sites More sharing options...
awebbdesigner Posted September 26, 2010 Author Share Posted September 26, 2010 I have changed the script to the following... <?php ini_set('display_errors', 1); error_reporting(E_ALL); include("../../connect.php"); # these settings should help set_time_limit(0); # going in as a blob from now on $stamp = mktime(); $safename = $_FILES['Filedata']['tmp_name']; $filename = $_FILES['Filedata']['name']; $size = $_FILES['Filedata']['size']; $type = $_FILES['Filedata']['type']; $fk = $_REQUEST['fk']; $sqlname = $stamp . "-" . $_FILES['Filedata']['name']; /// open and code in $fp = fopen($safename, 'r'); $content = fread($fp, filesize($safename)); $content = addslashes($content); fclose($fp); $big = mysql_query("SET max_allowed_packet=16777216"); $insertS = "INSERT INTO $tableb (pal, afield, bfield, cfield, dfield, efield, ffield, ablob) VALUES ('6', '$fk', '$filename', '$size', '$type', '$width', '$height', '$content')"; $errQ = mysql_query("INSERT INTO $tableb (pal, atext) VALUES ('1', '$insertS')"); $insertQ = mysql_query($insertS); print "<p><strong>Safename:</strong> $safename, <strong>Size:</strong> $size</p>"; print "<p><em>$insertS</em></p>"; print "1"; ?> I got... Safename: /Applications/MAMP/tmp/php/phpmIOmby, Size: 1846539 Then the query which looks fine, when I try to run the query printed in navicat it doesn't insert a row or give me an error message. I suspect this is to do with mysql not allowing posts over 1mb, so please can someone tell me the code to write in PHP that can overwrite this 1mb limit? Quote Link to comment https://forums.phpfreaks.com/topic/214363-large-upload-into-blob/#findComment-1115693 Share on other sites More sharing options...
awebbdesigner Posted September 26, 2010 Author Share Posted September 26, 2010 I added the following code... # helpful info $x = mysql_query("SELECT @@max_allowed_packet"); $y = mysql_fetch_array($x); print "<p>Max allowed packet is: " . $y[0]. "</p>"; And I got... Max allowed packet is: 1048576 The file I am trying to upload is Size: 1623807 So its definitely the packets. I have googled around and found a few solutions, one way is to split the file into chunks. I am going to try that and update this post with progress in case it's handy for others. Quote Link to comment https://forums.phpfreaks.com/topic/214363-large-upload-into-blob/#findComment-1115818 Share on other sites More sharing options...
awebbdesigner Posted September 27, 2010 Author Share Posted September 27, 2010 An update before I mark as solved. I wasn't able to update the max_allowed_packets during runtime locally on my mac using MAMP so I had to copy over a .cnf file and restart which worked a treat. Thankfully MOSSO cloud supports max_allowed_packets during runtime, so I can now upload upto 16mb into blob fields. This link was helpful for me to upload above 1mb locally on my Mac using MAMP: http://forum.mamp.info/viewtopic.php?f=2&t=6306 Thanks for all the help. Quote Link to comment https://forums.phpfreaks.com/topic/214363-large-upload-into-blob/#findComment-1116235 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.