Rename an upload
| From: | Steve Jackson | Date: | Wed, 11 Dec 2002 09:30:41 +0000 |
| Subject: | Rename an upload | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-127772@lists.php.net to get a copy of this message | ||
I'm trying to rename an uploaded file with the value of a select I have
in the uploaded form. Can someone point me in the right direction. The
PHP.net rename manual isn't helping a lot? My code:
//Form for upload
<form enctype="multipart/form-data" action="eshop_upload.php"
method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="25000">
<input type="file" name="userfile" size="18"
class="kapea">
<br><br>
<span class="adminisoleipa">Select the category to add the picture
to:<br><br>
<select name='category'>
<option value="">Please select...</option>
<?
while ($array = mysql_fetch_array($mysql))
{
echo "<option
value='{$array["catid"]}'>{$array["catname"]}</option>";
}
?>
</select>
</td>
</tr>
<tr><td><br>
<input type="submit" name="Submit" value="Submit"
class="nappi">
</form>
//eshop_upload.php
<?php
// Upload the picture to the selected directory and rename the file as
the category number.
if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name']))
{
copy($HTTP_POST_FILES['userfile']['tmp_name'],"http://www.violasystems.c
om/images/");
rename("($HTTP_POST_FILES['userfile']['tmp_name'])",
"$category");
}
else
{
echo "Possible file upload attack. Filename:"
.$HTTP_POST_FILES['userfile']['tmp_name']
}
?>
TIA.
Steve Jackson
Web Developer
Viola Systems Ltd.
http://www.violasystems.com
stephen.jackson@violasystems.com
Mobile +358 50 343 5159