Page 1 of 1

[SOLVED] Help with PHP File Uploads

Posted: Thu Feb 10, 2005 9:10 pm
by dardsemail
I have been trying to use the php upload script from the PHP.net site at http://www.php.net/manual/en/features.file-upload.php

Here is what I have thus far:

Code: Select all

<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="moveuploaded.php" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>
Then on moveuploaded.php I have the following:

Code: Select all

<?php
$uploadDir = '/myftpinfo/images/';
$uploadFile = $uploadDir . $_FILES&#1111;'userfile']&#1111;'name'];
print "<pre>";
if (move_uploaded_file($_FILES&#1111;'userfile']&#1111;'tmp_name'], $uploadFile))
&#123;
    print "File is valid, and was successfully uploaded. ";
    print "Here's some more debugging info:\n";
    print_r($_FILES);
&#125;
else
&#123;
    print "Possible file upload attack!  Here's some debugging info:\n";
    print_r($_FILES);
&#125;
print "</pre>";
?>
I am getting the following error:
Warning: move_uploaded_file(/myftpinfo/images/C22logo.jpg): failed to open stream: No such file or directory in /Library/WebServer/Documents/avocado/moveuploaded.php on line 2



Warning: move_uploaded_file(): Unable to move '/var/tmp/phpVXsYJI' to '/myftpinfo/images/C22logo.jpg' in /Library/WebServer/Documents/avocado/moveuploaded.php on line 2


Possible file upload attack! Here's some debugging info:
Array
(
[userfile] => Array
(
[name] => C22logo.jpg
[type] => image/jpeg
[tmp_name] => /var/tmp/phpVXsYJI
[error] => 0
[size] => 12774
)


)
I haven't included the myftpinfo details here but I'm using mydomain.com... but I suspect that might be the problem. What should the format for specifying the ftp location be? Is that the issue I have above?

Thanks so much for any insight!!!

Posted: Thu Feb 10, 2005 9:25 pm
by feyd
you sure you have a folder in the root of the server? 'cause that's where you are trying to send it.. ;)

Posted: Thu Feb 10, 2005 9:32 pm
by dardsemail
ahhh... I thought something was wrong there.

How would I figure out where to send it?

Posted: Thu Feb 10, 2005 9:36 pm
by feyd
You can use $_SERVER['DOCUMENT_ROOT'] to fetch your server's web root, and add on folders from there..

Posted: Thu Feb 10, 2005 9:44 pm
by dardsemail
Got it! Thanks so much for your help!!!