PDA

View Full Version : Help !


leebo
02-26-2002, 03:42 PM
I need to know if you could possibly help me ??

I have to upload a file lets say....c:/windows/desktop/picture.gif

I need to change the name of the file before
saving it to the server the name will come through on the form with the file
path etc...

i.e upload.php?changename=example

this making the filename example.gif instead of the picture.gif

Could you please help me i`m so lost.

Regards

Lee

Millencolin
02-26-2002, 09:59 PM
Umm can't you just rename it on your computer? Or when you upload it, you can usually rename the file to whatever you want.
I would just rename it before i upload it, like normally, right click and "rename" it.
Unlesss your talking about something else that i have no idea of what your saying.

leebo
02-27-2002, 02:50 AM
No i`m building a site for users to upload a picture of them selves but say 2 people have the picture lee.gif then it will overwrite one another so i need to have some code that will rename all files to the users username before uploading.

i.e. if you wanted to have a button on here where people could upload a picture of them selves and had over 20,000 members then someone could have the same gif name and would cause a problem.

Cheers

Hitek
02-27-2002, 03:02 AM
Last time I checked, when a user uploaded a file through a php script, it was required to copy the file from the temp directory to it's permanent home.
You can simply rename the file inside the copy function.

leebo
02-27-2002, 01:40 PM
Yes it does copy it first into a temp directory then copys into the web server. But do you know how to rename the file whilst in the temp folder ? I more of a asp person not php but need this working for my site.

Cheers

Sintax
02-27-2002, 04:48 PM
I just made a script were people upload images and it displays it... It maybe what your looking for. if not you can see how i rename the files.

http://www.hotscripts.com/Detailed/14189.html

el_robert
03-11-2002, 11:18 PM
this is in no way complete but hopefully it will get you going in the right direction.

All it does is take the uploaded file named "$myfile" and renames it by prepending the user name and a hyphen to the original name.

When you need to get the right file, just use :

$ar = explode("-",$image_file_name);
$user_name = $ar[0];


this is assuming you don't allow hyphens in the user name.

It works pretty well for me, there is about 140,000 images that were uploaded this way so far and no problems.

form:

<form ENCTYPE="multipart/form-data" method=post action=process_upload.php>
<input name=myfile type=file>
<input type=submit value="Click to upload">
</form>



process_upload:

//get the original file name
$og_name = $HTTP_POST_FILES['userfile']['name'];

//set the path where it is going to go
$path = "/my/path/";

//set the new file name by prepending the user name to the original file name
$new_file_name = $path.$user_name."-".$og_name;

//move it
move_uploaded_file($myfile,$new_file_name);