note 32674 added to features.file-upload
| From: | pnieuwdorp at yahoo dot com | Date: | Wed, 04 Jun 2003 08:56:52 +0000 |
| Subject: | note 32674 added to features.file-upload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-49694@lists.php.net to get a copy of this message | ||
I got a problem with uploading files larger then 1MB via http post and save it in MySQL.
I read that you can split files and save each part and then combine the parts.
here's my code; can anyone tell me why it doesn't work?
it gives an empty blob when i post a file larger then 1mb.
when i post a file smaller then it works fine.
TABLE:
CREATE TABLE test (
id INT not null AUTO_INCREMENT,
name VARCHAR (64) not null,
type VARCHAR (64) not null,
length INT not null,
content MEDIUMBLOB not null,
PRIMARY KEY (id)
)
CODE:
define("MAX_SQL",906240);
$fp = fopen($HTTP_POST_FILES[file][tmp_name],"rb");
$sql = "INSERT INTO test (name,type,length)
VALUES
('" . $HTTP_POST_FILES[file][name] . "','" .
$HTTP_POST_FILES[file][type] . "','" .
filesize($HTTP_POST_FILES[file][tmp_name]) . "')";
mysql_query($sql) or die("Bad luck1");
$id = mysql_insert_id();
$counter = 0;
while (!feof($fp)){
$counter = $counter + 1;
$data = addslashes(fread($fp,MAX_SQL));
// check if this is the first time you insert the blob so don't use concat
if ($counter == 1)
{
$sql = "UPDATE test SET content = '$data' WHERE id = '$id'";
}
else
{
$sql = "UPDATE test SET content = CONCAT(content,'$data') WHERE id =
'$id'"; }
mysql_query($sql) or die("Update with blob fails");
}
----
Manual Page -- http://www.php.net/manual/en/features.file-upload.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32674
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32674&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32674&report=yes