The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
Uploading files with PHP
First of all i must say what a great new Logo it is well smart
I have yet another problem using php, I have got a page to upload a picture but i need to find away to change the name of the file to the username. i.e. a user find a picture they want lets say c:/windows/desktop/picture1.gif The username will be sent via another page www.example.com?username=leebo I need to save the file as the username i.e. leebo.gif Any ideas ? Cheers |
#2
|
||||
|
||||
Post the code you are using to save the picture now.
Basically replace $_FILES['imagefile']['filename'] with the username when copying it. |
#3
|
||||
|
||||
Thanks here is the main code which uploads it :
function do_upload () { global $uploadfile, $uploadfile_name, $uploadfile_type, $uploadfile_size; global $local_file, $error_msg; //if file specified isn't a gif/jpeg, output error message if (($uploadfile_type != "image/gif") && ($uploadfile_type != "image/jpeg") && ($uploadfile_type != "image/pjpeg")) { $error_msg .= "Your file is not a web graphic (GIF/JPG).\n"; } // Change $upload_dir to the directory that you have write permission (777) for on your server $upload_dir = "tempphotos"; $local_uploadfile = "$upload_dir/$uploadfile_name"; //if there's no error, print info about the uploaded file if (!$error_msg && copy($uploadfile, $local_uploadfile)){ echo "Redirecting back to site please wait...... "; echo" <script> window.location=\"cars.asp\" </script> "; } Cheers |
#4
|
||||
|
||||
First you should use $_FILES when handling uploads, more secure.
Other than that, in $local_uploadfile replace $uploadfile_name with $username (don't forget to globalize it in the function), and append either .gif or .jpeg according to $uploadfile_type. |
#5
|
||||
|
||||
Thanks firefly
BUT i`m not a PHP person so if you could help me to rename the file that would be great. I got the filename to rename but not the ext. If i uploaded lee.gif i got it to rename it $username with out the .gif - how can i just change the name and leave the extension in place ?? |
#6
|
||||
|
||||
Use this as the filename:
PHP Code:
PHP Code:
|
#7
|
||||
|
||||
GREATTTTTTTTTTTTTTTTTT !
Thats done it cheers for all your help firefly, you know your onions ! |
#8
|
||||
|
||||
No probs, leebo.
|
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|