Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-26-2002, 04:48 PM
leebo's Avatar
leebo leebo is offline
 
Join Date: Nov 2001
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
Reply With Quote
  #2  
Old 02-27-2002, 05:03 AM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Post the code you are using to save the picture now.
Basically replace $_FILES['imagefile']['filename'] with the username when copying it.
Reply With Quote
  #3  
Old 02-27-2002, 03:55 PM
leebo's Avatar
leebo leebo is offline
 
Join Date: Nov 2001
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #4  
Old 02-27-2002, 04:01 PM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 03-05-2002, 04:42 PM
leebo's Avatar
leebo leebo is offline
 
Join Date: Nov 2001
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 ??
Reply With Quote
  #6  
Old 03-05-2002, 04:52 PM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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); 
Reply With Quote
  #7  
Old 03-05-2002, 05:05 PM
leebo's Avatar
leebo leebo is offline
 
Join Date: Nov 2001
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

GREATTTTTTTTTTTTTTTTTT !

Thats done it cheers for all your help firefly, you know your onions !
Reply With Quote
  #8  
Old 03-05-2002, 05:08 PM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No probs, leebo.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:52 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08433 seconds
  • Memory Usage 2,234KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete