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>