|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-09-04 22:26 UTC] jani@php.net
[2007-09-12 01:00 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 18:00:01 2025 UTC |
Description: ------------ Scenario: Trying to move potentially large files into MySQL database using the 'Insert into....content=LOAD_FILE('$tmpnam')' command where $tmpname=$_FILES['tmp_name']; gave an empty content. using the command move_uploaded_file($tmpname,"tmp/foo") and Load_File('/tmp/foo') also failed..badly. the browser hung.. using copy($tmpname,'/tmp/foo'); insert..content=LOAD_FILE('/tmp/foo') WORKED!! I suspect the new files do NOT exist (properly) for a third party program like Mysqld to find..until PHP exits and flushes its buffers. However it is not possible to delay calling Mysql until after the script exits. What would be nice is a sync() call that would force all open file handles to be updated to the OS. I have added the workaround note to the move_uploaded_file() docs. I am happy to test any proposed solutions - at least for the next few days while I am working on this. The email is VALID Reproduce code: --------------- // this code sits inside a loop which sets $index to correspond to one of many possible file uploads $filename=$_FILES[$index]["name"]; //orig filename $filesize= $_FILES[$index]["size"]; // the size in bytes of the uploaded file $tmpname=$_FILES[$index]["tmp_name"]; // the name of the temporary copy of the file stored on the server // If we have a new file, then we archive the old one and insert the new if ($filename != "" && $filesize != 0) // we have a new file { // copy($tmpname,"/tmp/foo"); workaround $query="update project_files set current='no' where id='".$file_id."'"; mysql_query($query); // Poof! Gone! $query=sprintf("insert into project_files set project_id='%s',current='yes',date='%s' ,user='%d', size='%d', description='%s', name='%s', content=LOAD_FILE('%s')", $project_id, date('Y-m-d'), $employee_id, $filesize, $filedescription, $filename, // "/tmp/foo");//hack but works $tmpname); // doesn't work. Empty content mysql_query($query); } Expected result: ---------------- I would have hoped that the uploaded file would have ended up in project_files.content. It was in fact null unless I used the copy() command to create a DUPLICATE of $tmpname.. move_uploaded_file() was even worse.It behaved as though the file wasn't even there at all, rather than zero length. I COULD have added the stream directly to SQL with a content=addslashes() from the file, but the thought of adding slashes to e.g. 10Mbyte bitmap, and having Mysql API remove them was too ghastly to contemplate. Actual result: -------------- project_files.content=0; !! :-)