Jump to content

Large upload into blob


awebbdesigner

Recommended Posts

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";

 

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

 

 

 

Link to comment
Share on other sites

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.

 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.