From:             tnp at shaman dot co dot uk
Operating system: Debian Etch
PHP version:      5.2.4
PHP Bug Type:     Filesystem function related
Bug description:  Uploaded files empty UNTIL PHP EXITS?

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;
!! :-)

-- 
Edit bug report at http://bugs.php.net/?id=42550&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=42550&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=42550&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=42550&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=42550&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=42550&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=42550&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=42550&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=42550&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=42550&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=42550&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=42550&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=42550&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=42550&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=42550&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=42550&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=42550&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=42550&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=42550&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=42550&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=42550&r=mysqlcfg

Reply via email to