PHP posting binary file not working

PHP posting binary file not working

Posted by: arajakum
Posted on: 2005-11-03 13:36:00

PHP file upload seems broken on Dreamhost. What do I need to do to get it working? Sample code I got from the web is below, as well as the response for a wget which indicates the file went across successfully, but there is no data in the $_FILES array at all.

[grant]$ wget -S --post-file=testlog -O junk http://www.victrio.com/vapp/data/testup.pcgi

--13:19:33-- http://www.victrio.com/vapp/data/testup.pcgi
=> `junk'
Resolving www.victrio.com... 64.111.105.20
Connecting to www.victrio.com[64.111.105.20]:80... connected.
HTTP request sent, awaiting response...
1 HTTP/1.1 200 OK
2 Date: Thu, 03 Nov 2005 21:19:33 GMT
3 Server: Apache/1.3.33 (Unix) DAV/1.0.3 mod_fastcgi/2.4.2 mod_gzip/1.3.26.1a PHP/4.3.10 mod_ssl/2.8.22 OpenSSL/0.9.7e
4 X-Powered-By: PHP/4.3.10
5 Connection: close
6 Content-Type: text/html




<pre>
<?php
$root = realpath($_SERVER['DOCUMENT_ROOT']);
$uploaddir = $root.'/stuff/';
$uploadfile = $uploaddir . $_FILES['userfile']['name'];
echo ($uploadfile);

print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
print "File is valid, and was successfully uploaded. ";
print "Here's some more debugging info:n";
print_r($_FILES);
} else {
print "Possible file upload attack! Here's some debugging info:n";
print_r($_FILES);
}

?>
</pre>


Re: PHP posting binary file not working

Posted by: Atropos7
Posted on: 2005-11-03 14:54:00

For all I know, you PHP code works. I haven't tried it.

What I find interesting is you neglected to mention if the file you specified in the call to wget is formatted properly for the POST method or not.

If you don't know what I am talking about, you need to read this: RFC 2388 - Returning Values from Forms: multipart/form-data

Otherwise, try using a web browser instead of wget.




cool Perl / MySQL / HTML+CSS

Re: PHP posting binary file not working

Posted by: arajakum
Posted on: 2005-11-03 14:59:00

Ok - more info. phpinfo() reports that upload_tmp_dir is not set. If it's not set, then php won't even bother uploading the file. So Dreamhost is going to have to figure out how to set upload_tmp_dir in php safe mode :P. Anyway, I did try your suggestion and still no luck. Try running the following code which is from http://www.faqts.com/knowledge_base/view.phtml/aid/16763/fid/62
and you'll see why this is so frustrating...


<HTML>
<TITLE>
File upload
</title>
<body>
<B>File upload</b>
<form enctype="multipart/form-data" action="<?PHP echo $PHP_SELF ?>"
method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
Send this file:
<input name="userfile" type="file">
<input type="submit" name="submit" value="Send File">
</form>
</body>
<?PHP

// copy to this directory
$dir="./uploads/";

// copy the file to the server
if (isset($submit)){

if (!is_uploaded_file ($userfile)){

echo "<b>$userfile_name</b> couldn't be copied !!";
}

// check whether it has been uploaded
if (is_uploaded_file ($userfile)){
move_uploaded_file($userfile,$dir.$userfile_name) ;}

echo "<b>$userfile_name</b> copied succesfully !!";
}

?>


Re: PHP posting binary file not working

Posted by: scjessey
Posted on: 2005-11-03 15:46:00

In reply to:

PHP file upload seems broken on Dreamhost


It looks like you are correct. My hand-written gallery application is no longer accepting file uploads either. I haven't used it for a while, so I couldn't say exactly when it stopped working.

Re: PHP posting binary file not working

Posted by: dreamuser
Posted on: 2005-11-04 13:56:00

I think uploading is completely broken. I am experiencing the same issue with perl. See http://discussion.dreamhost.com/showflat.pl?Cat=&Board=forum_programming&Number=33000&page=0&view=collapsed&sb=5&o=14&part=

Re: PHP posting binary file not working

Posted by: hankhofler
Posted on: 2005-11-10 08:59:00

Has this been fixed? I am also experiencing problems. Particularly with getting a value from $_FILES['userfile']['tmp_name'].

HH

Re: PHP posting binary file not working

Posted by: Atropos7
Posted on: 2005-11-10 11:07:00

In reply to:

I think uploading is completely broken. I am experiencing the same issue with perl.


Nothing wrong with uploading. Your Perl code leaves much to be desired.

Try this instead.

http://atropos.openvein.org/web/dreamhost/perl/source/upload.pl


cool Perl / MySQL / HTML+CSS

Tags: php file uploaddreamhostwgethttpsuccessfully