Page 1 of 1

UPLOADING and RENAMING FILES PROBLEMS, PLEASE HELP

Posted: Sat Nov 30, 2002 3:45 pm
by urb
Im try to upload files and text of a form. From that form i mix post and files. what i am trying to do is upload a file and have it named to one of the fields of the post.

For example.
I have a text box with name id, and a file box for an image named thumb_img for the uploading

my code in the php upload script is as follows for the uploading of the file and renaming.

copy($_FILES[thumb_img][tmp_name], "/home/webtemp/public_html/images/t/thumbs/".$_FILES[thumb_img][name])
rename("/home/webtemp/public_html/images/t/thumbs/".$_FILES[thumb_img][name], "/home/webtemp/public_html/images/t/thumbs/".$_POST[id].".gif");
or die("Couldn't copy the thumb image file");



Can someone please, I been stuck with this problem for awhile.


Thank you
- urb -

Posted: Sat Nov 30, 2002 11:11 pm
by volka
(this post belongs to the PHP forum ;) )

why copying it to a file with the original filename in the first place?
try

Code: Select all

$dest = '/home/webtemp/public_html/images/t/thumbs/'. $_POSTї'id'] . '.gif';
move_uploaded_file($_FILESї'thumb_img']ї'tmp_name'], $dest)
/* no ';' between the last statement and "or ..." */
   or die('Couldn''t copy the thumb image file: ' . $_FILESї'thumb_img']ї'tmp_name'] . '->' . $dest);

Posted: Sun Dec 01, 2002 12:25 am
by mydimension
now moved to the PHP Forum

Posted: Sun Dec 01, 2002 5:53 pm
by urb
Im not trying move a file that is already uploaded. I want to be able to upload multiple files and have them all renamed from a post field $_POST[id]. I problem i am having is have the files actually get uploaded and renamed during the process. Someone told me i can have a simple command line do both upload and rename

for example:

copy($_FILES[thumb_img], "/home/webtemp/public_html/images/t/thumbs/".$_FILES[thumb_img].".gif")
or die("Couldn't copy the thumb image file");


The code above in the example returns an error:

Warning: Unable to open 'Array' for reading: No such file or directory in /home/webtemp/public_html/ver1/admin/do_addtemplate.php on line 13


Can someone please help me with this simple problem

Posted: Sun Dec 01, 2002 6:31 pm
by volka
please read http://www.php.net/manual/en/features.file-upload.php
it's all explained there