RE: [PHP] Upload Problem
| From: | Tom Walsh | Date: | Wed, 13 Sep 2000 13:58:48 +0000 |
| Subject: | RE: [PHP] Upload Problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-16565@lists.php.net to get a copy of this message | ||
The way file uploads work is this:
When a file is uploaded the variable that is defined in the HTML Form
represents the file pointer. So in your case $userfile is the location of
the file in the tmp dir. One of the neat things about a file upload is that
PHP gives you other info about the file by default.
$userfile_name is the filename defined by the user (the original filename on
the users computer)
$userfile_size is the size of the file
$userfile_type is the mime type of the uploaded file
What you want to do is this:
$timestamp = time();
$image= $timestamp.$userfile_name; //gives the file a unique name
exec("mv $userfile /path/to/your/html/dir/$image"); //moves the file into
your webspace
A word of caution... While file uploads are great you need to include some
sort of checking to make sure people are not uploading malicious code such
as a PHP script that could take the passwd file and e-mail to themselves...
HTH
Tom Walsh
>
> I'm working on getting a standard upload script to work, but am having
> problems renaming the temporary file. I get this error:
>
> Warning: Rename failed (Invalid cross-device link)
>
> The value of the temporary file was:
> /tmp/php16419aaa
>
> The final name was supposed to be:
> nnamer.html
>
> and the code used to rename is:
> rename($userfile, $userfile_name);
>