Reply
Uploading image and renaming it
Old 07-24-2004, 02:55 PM Uploading image and renaming it
Junior Talker

Posts: 2
Trades: 0
I've been studying file uploading from PHP.net and I got files uploaded. The only problem I have now is that I can't define what I want image name to be when it's in server. For example I upload image.png and I want that it's name in server is 1.png.

I have now this script:
I've tried changing $uploadfile = $uploaddir . $_FILES['image']['name']; to
$uploadfile = $uploaddir . "1.png"; but it doesnt work after i do that.

PHP Code:


PHP Code:
$uploaddir '/home/mikko/www/images/upload/'
        
$uploadfile $uploaddir $_FILES['image']['name']; 
        print 
"<pre>"
        if (
move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile )) 
            { 
                print 
"File is valid, and was successfully uploaded. "
                print 
"Here's some more debugging info:\n"
                
print_r($_FILES); 
            } 
        else 
            { 
                print 
"Possible file upload attack!  Here's some debugging info:\n"
                
print_r($_FILES); 
            } 
        print 
"</pre>"
What should I change in this script so that image name would always be 1.png? I really have been thinking this but I haven't got it work. Usually when I change something it just goes to that else

- Keripukki
kerari is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 04-25-2008, 12:54 PM Re: Uploading image and renaming it
Experienced Talker

Posts: 46
Trades: 0
just do copy();

don't forget to do a is_uploaded_file() first.

jeff
__________________
Squirrel bombing -> Home of the crasher squirrel
jeff_oneil is offline
Reply With Quote
View Public Profile Visit jeff_oneil's homepage!
 
Old 04-25-2008, 01:21 PM Re: Uploading image and renaming it
addonchat's Avatar
Super Talker

Posts: 113
Name: Chris Duerr
Trades: 0
$uploadfile = $uploaddir . "1.png";

http://us3.php.net/move_uploaded_file

You can also use rename()

http://www.php.net/manual/en/function.rename.php
__________________
Chris Duerr
AddonChat Java Chat Software
http://www.addonchat.com/ - Affiliate Program
addonchat is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Uploading image and renaming it
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.11043 seconds with 13 queries