Re: More File Uploading Problems

From: Date: Sat, 20 Jul 2002 03:43:52 +0000
Subject: Re: More File Uploading Problems
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-108620@lists.php.net to get a copy of this message
I know that when I upload files I use a path that is relavent to the dir structure on the server: linux | /home/hosting/clients/myclient/storefile/filename.extension windows | c:/webdocs/hosting/clients/myclient/filename.extension You get the idea, I don't believe copy() works with a "non-local" path like "http://www.mydomain.com/~demodocs/ProjDocs/". Roger Lewis wrote:
I see from a search of the archives that there are many others with problems uploading files to servers, but I haven't come across my problem yet. As a test, I took code direct from the php manual and tried to upload a file from my browser to the server. I created a file called getfiles.php in which I put the form that the user uses to upload his file: (I've left the text and formatting out of this post) <form enctype="multipart/form-data" name="frmUploadFile" action="storefile.php" method="post"> <input type="file" name="fileUpload" size="20"> <input type="submit" value="Upload this file" name="cmdSubmit"> </form> I created another file called storefile.php that is supposed to copy or move the uploaded file from the default temp directory to the assigned directory. <?php // In PHP earlier then 4.1.0, $HTTP_POST_FILES should be used instead of $_FILES. if (is_uploaded_file($HTTP_POST_FILES['fileUpload']['tmp_name'])) { copy($HTTP_POST_FILES['fileUpload']['tmp_name'], "http://www.mydomain.com/~demodocs/ProjDocs/"); } else { echo "Possible file upload attack. Filename: " . $HTTP_POST_FILES['fileUpload']['name']; } /* ...or... */ move_uploaded_file($HTTP_POST_FILES['fileUpload']['tmp_name'], "http://www.mydomain.com/~demodocs/ProjDocs/"); ?> Both of the above files are put in the web site root, http://www.mydomain.com/~demo/ When I point my browser to getfiles.php the form appears and I can browse for files from my hard drive. But when I upload the file, I get the following messages: Warning: Unable to create 'http://www.mydomain.com/~demodocs/ProjDocs/': No such file or directory in /home/sites/home/users/demo/web/storefile.php on line 15 Warning: Unable to create 'http://www.mydomain.com/~demodocs/ProjDocs/': No such file or directory in /home/sites/home/users/demo/web/storefile.php on line 20 Warning: Unable to move '/tmp/phpAZoDZh' to 'http://www.mydomain.com/~demodocs/ProjDocs/' in /home/sites/home/users/demo/web/storefile.php on line 20 It appears that the tmp file has been uploaded, but no amount of fiddling with the end file location, or the location of getfiles.php or storefiles.php, has changed anything but the wording of the error message. I changed $HPPP_POST_FILES TO $_FILES, but that gave me the "Possible file upload attack... " message. I'm using PHP 4.0.6. The chmod for ../ProjDocs/ is 755. I don't know what the permissions are for the temp directory, nor am I certain as to where exactly it is. Does anyone have any thoughts as to why this is happening. Any help is appreciated. Roger Lewis


« previous php.general (#108620) next »