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 -
UPLOADING and RENAMING FILES PROBLEMS, PLEASE HELP
Moderator: General Moderators
(this post belongs to the PHP forum
)
why copying it to a file with the original filename in the first place?
try
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);- mydimension
- Moderator
- Posts: 531
- Joined: Tue Apr 23, 2002 6:00 pm
- Location: Lowell, MA USA
- Contact:
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
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
please read http://www.php.net/manual/en/features.file-upload.php
it's all explained there
it's all explained there