UPLOADING and RENAMING FILES PROBLEMS, PLEASE HELP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
urb
Forum Newbie
Posts: 21
Joined: Fri Nov 08, 2002 1:08 am
Location: Los Angeles, California

UPLOADING and RENAMING FILES PROBLEMS, PLEASE HELP

Post 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 -
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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);
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

now moved to the PHP Forum
urb
Forum Newbie
Posts: 21
Joined: Fri Nov 08, 2002 1:08 am
Location: Los Angeles, California

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

please read http://www.php.net/manual/en/features.file-upload.php
it's all explained there
Post Reply