PHP posting binary file not working

software development

#1

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

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

print "
";
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);
}

?>

#2

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


#3

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…

File upload File upload Send this file: <?PHP

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

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

if (!is_uploaded_file ($userfile)){

echo “$userfile_name couldn’t be copied !!”;
}

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

echo “$userfile_name copied succesfully !!”;
}

?>


#4

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.


Simon Jessey
Keystone Websites | si-blog


#5

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=


#6

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

HH


#7

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