[PHP] Rename an upload
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 brbr span class=adminisoleipaSelect the category to add the picture to:brbr 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 trtdbr 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 [EMAIL PROTECTED] Mobile +358 50 343 5159 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Rename an upload
On Wednesday 11 December 2002 17:30, Steve Jackson wrote: 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: What is the problem? //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/); You've copied the uploaded file to another directory ... rename(($HTTP_POST_FILES['userfile']['tmp_name']), $category); ... but now you're renaming the [temporary] uploaded file? Shouldn't you be renaming the above copied file? In fact you should be able to do it in a single step by copying the uploaded file to its new destination and new filename. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Age before beauty; and pearls before swine. -- Dorothy Parker */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Rename an upload
On Wednesday 11 December 2002 17:30, Steve Jackson wrote: 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: What is the problem? I can't figure out how to upload the file with the name I need. The rename function in the manual says Its: rename(string1,string2) Ie. ?php rename(/tmp/tmp_file.txt, /home/user/login/docs/my_file.txt); ? I want to rename the file copied to the server to the name of the select value I sent in my previous post (held in the variable $category) so basically How do I do that? Where do I do it in the upload script also? You mention I should be able to do it in a single step, that would be ideal but again how do I do it? Do I need to put the uploaded file in a variable so I can rename the copied image? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Rename an upload
On Wednesday 11 December 2002 18:55, Steve Jackson wrote: On Wednesday 11 December 2002 17:30, Steve Jackson wrote: 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: What is the problem? I can't figure out how to upload the file with the name I need. The rename function in the manual says Its: rename(string1,string2) Ie. ?php rename(/tmp/tmp_file.txt, /home/user/login/docs/my_file.txt); ? I want to rename the file copied to the server to the name of the select value I sent in my previous post (held in the variable $category) so basically How do I do that? Where do I do it in the upload script also? You mention I should be able to do it in a single step, that would be ideal but again how do I do it? Do I need to put the uploaded file in a variable so I can rename the copied image? if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) { copy($HTTP_POST_FILES['userfile']['tmp_name'],http://www.violasystems.c om/images/$category); That should do it in a single step. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Many Myths are based on truth -- Spock, The Way to Eden, stardate 5832.3 */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php