Re: More File Uploading Problems

From: Date: Sat, 20 Jul 2002 07:31:54 +0000
Subject: Re: More File Uploading Problems
Groups: php.general 
Request: Send a blank email to php-general+get-108644@lists.php.net to get a copy of this message
><form enctype="multipart/form-data" name="frmUploadFile" >action="storefile.php" method="post"> ><input type="file" name="fileUpload" size="20"> I'm not sure size= has any meaning for a FILE input... shrug. ><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/"); Don't use "copy". Use move_uploaded_file. More importantly, you *CANNOT* move a file to a URL. You have to move it to a *FILE* on your web-server computer. The path should probably be something like: "/www/mydomain.com/demodocs/ProjDocs/$fileUpload_name" Note that you need a file NAME, not just a directory. >} 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/ >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. You also will need that directory, not a URL, to be some place that the PHP user has WRITE access to. In a shared ISP environment, that generally means you have to make it world-writable: chmod 666 /www/mydomain.com/demodocs/ >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. The temp directory seems to be working fine. 755 will not cut it. 666 or 766. Or even, I suppose, 622, but then you'll need to have some kind of cron job running as a real user (you) to *READ* the files uploaded, since nobody else will be able to read them. -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#108644) next »