ID:               42550
 Updated by:       [EMAIL PROTECTED]
 Reported By:      tnp at shaman dot co dot uk
-Status:           Open
+Status:           Feedback
 Bug Type:         Filesystem function related
 Operating System: Debian Etch
 PHP Version:      5.2.4
 New Comment:

Can you please provide a short and self-contained script that we can
just copy'n'paste and run to see what the actual problem is?
>From first glance this seems like you just haven't really understood
how the file uploading works.


Previous Comments:
------------------------------------------------------------------------

[2007-09-04 20:50:18] tnp at shaman dot co dot uk

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 this bug report at http://bugs.php.net/?id=42550&edit=1

Reply via email to