vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Uploading files with PHP (https://vborg.vbsupport.ru/showthread.php?t=35471)

leebo 02-26-2002 04:48 PM

Uploading files with PHP
 
First of all i must say what a great new Logo it is well smart :D

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

Admin 02-27-2002 05:03 AM

Post the code you are using to save the picture now.
Basically replace $_FILES['imagefile']['filename'] with the username when copying it.

leebo 02-27-2002 03:55 PM

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 ;)

Admin 02-27-2002 04:01 PM

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.

leebo 03-05-2002 04:42 PM

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 ??

Admin 03-05-2002 04:52 PM

Use this as the filename:
PHP Code:

$username '.' substr(strrchr($uploadfile_name'.'), 1

So $local_uploadfile would look like this:
PHP Code:

$local_uploadfile $upload_dir '/' $username '.' substr(strrchr($uploadfile_name'.'), 1); 


leebo 03-05-2002 05:05 PM

GREATTTTTTTTTTTTTTTTTT !

Thats done it cheers for all your help firefly, you know your onions ! :D

Admin 03-05-2002 05:08 PM

No probs, leebo. :)


All times are GMT. The time now is 12:35 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01035 seconds
  • Memory Usage 1,728KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete