note 77579 added to function.move-uploaded-file
| From: | tnp at shaman dot co dot uk | Date: | Tue, 04 Sep 2007 20:20:11 +0000 |
| Subject: | note 77579 added to function.move-uploaded-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130180@lists.php.net to get a copy of this message | ||
I may well also report this as a bug, but in the meantime I'll document what I have seen so
far.
What I wanted to do, was take the uploaded temporary filename and pass it to MySql as part of a
load_file injection into a BLOB to store the file contents.
My first attempt was of an indexed array..
$filename=$_FILES[$index]["name"];
$filesize= $_FILES[$index]["size"];
$tmpname=$_FILES[$index]["tmp_name"];
followed by:-
$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,
$tmpname);
mysql_query($query);
This gave me an empty content field. Zero bytes.
I took the echo $query string and applied it to MtySql interpreter. With a suitable filename it
worked..well after fixing a few database perms..but no joy from PHP still.
I found this page and tried adding:-
move_uploaded_file($tmpname)"/tmp/foo");
$tmpname-"/tmp/foo";
before setting up the query.
That was worse. The browser just hung on me.
Then I tried
copy($tmpname,"/tmp/foo");
$tmpname="/tmp/foo";
That worked!?*&^
My CONJECTURE is that PHP has a meta file-system running, and the environment the program sees is
NOT reflected into the OS (Debian etch, in this case) until it closes and flushes its buffers.
Copy() does in fact seem to result in a real disk write, but move_uploaded_file() does not, so when
the name was passed to Mysqld, it didn't exist, or had zero content or maybe with a large file
truncated content.
I can see the point of this: faster response for web browsers who get the program HTTP output over
with before it settles down to its housekeeping, but in this case it's a bit of a disaster.
What is needed is a way to force the buffers to flush if that is what is going on...
----
Server IP: 69.147.83.197
Probable Submitter: 80.168.244.139
----
Manual Page -- http://www.php.net/manual/en/function.move-uploaded-file.php
Edit -- https://master.php.net/note/edit/77579
Del: integrated -- https://master.php.net/note/delete/77579/integrated
Del: useless -- https://master.php.net/note/delete/77579/useless
Del: bad code -- https://master.php.net/note/delete/77579/bad+code
Del: spam -- https://master.php.net/note/delete/77579/spam
Del: non-english -- https://master.php.net/note/delete/77579/non-english
Del: in docs -- https://master.php.net/note/delete/77579/in+docs
Del: other reasons-- https://master.php.net/note/delete/77579
Reject -- https://master.php.net/note/reject/77579
Search -- https://master.php.net/manage/user-notes.php