Reply
Some help with this please!
Old 12-03-2008, 08:17 AM Some help with this please!
rolda hayes's Avatar
Wannabe Adventurer...

Posts: 642
Name: Darren
Location: England
Any advise on this would be great...

With this script, a user can upload some images to a folder on the server.
The images either have the same name when uploaded or they are randomized. What I need, is for the images to keep their original file names but have the username of the person before them.

i.e user99_image1.jpg user99_image2.jpg and so on.

to get to this upload page the user has to be signed in so Im guessing (and only guessing mind...!) that it will be somethig to do with changing

$fileName = $_FILES[file][name][$i];

to something like

$fileName = $_SESSION[LOGIN_NAME][name][$i];

or something like that??

PHP Code:
<?php
    
        
# The script is designed to allow you to upload multiple files in one go, the script also presents you with the variable option
    # of keeping a files name or randomly renaming it.
    # Remember, there maybe a a upload limit set by the server of 2MB, you can change this by changing the php.ini if you have access
    #**************************************************************************************************


    ###/ VARIABLES - CHANGE ACCORDINGLY
    
define("VAR_BASE_DIRECTORY",    "/var/www/vhosts/*******/subdomains/test/httpdocs/");                 #/ Your webhosting directory
    
define("VAR_UPLOAD_FOLDER",        "uploads/");                 #/ Chmod directory 777 for successful upload
    
define("VAR_UPLOAD_DIRECTORY",    VAR_BASE_DIRECTORY.VAR_UPLOAD_FOLDER);         #/ DO NOT EDIT
    
define("VAR_UPLOAD_FIELDS",        4);                                         #/ Set number of upload fields
    
define("VAR_FILENAME_KEEP",        1);                                            #/ If set to 0 (Zero) the filename will generate randomly, if 1 (One) it will maintain filename


    ##/ Function that displays forms and is called by default
    
function defaultForm()
    {
        
        echo 
"<form method=\"post\" enctype=\"multipart/form-data\">\n";
            
            for(
$i=0$i VAR_UPLOAD_FIELDS$i++)
            {        
                  echo 
"Upload field ".$i." &nbsp;<input name=\"file[]\" type=\"file\" id=\"file[]\" /><br />\n";
            }
            
        echo 
"<input name=\"Submit\" type=\"submit\" value=\"Submit\">\n";
        echo 
"<input name=\"filter\" type=\"hidden\" value=\"processForm\">\n";        ##/ hidden value points the switch to processing
        
echo "</form>\n";
        
        return;
        
    }
    
#/ End of defaultForm

    ##/ Function that displays forms and is called by default
    
function processForm()
    {
            
        for(
$i=0$i VAR_UPLOAD_FIELDS$i++)
        {
            echo 
"Upload field $i ";

            if(!empty(
$_FILES[file][size][$i])) 
            { 
                if(
VAR_FILENAME_KEEP==1)
                {
                    
##/ File maintaining upload name
                    
$fileName     $_FILES[file][name][$i];
                }
                else
                {
                    
##/ Filename randomized
                    
$fileName     rand(1,4000).rand(1,4000).rand(1,4000).rand(1,4000).rand(1,4000).'.' substr($_FILES[file][name][$i], -3);
                }
                
                
##/ Creating reference address 
                
$newLocation     VAR_UPLOAD_DIRECTORY.$fileName;
                
                if(!
copy($_FILES[file][tmp_name][$i],$newLocation)) 
                {
                    echo 
"<b>Failed - ".$_FILES[file][name][$i]." would not copy to ".$newLocation."</b> (Check your upload directory and permissions)";
                }
                else
                {
                    
###/ SUCCESS /###
                    
                    #/ Stripping of VAR_BASE_DIRECTORY for better viewing and linking
                    
$urlShow str_replace(VAR_BASE_DIRECTORY,'',$newLocation); 
                    
                    echo 
"<b>Uploaded successfully - <a href=\"$urlShow\" target=\"_blank\">$urlShow</a></b>";
                }
            } 
            else
            {
                echo 
"<b>No file uploaded</b>";
            }
            echo 
"<br />";
        }
        return;
    }
    
#/ End of processForm
    

    ##/ This object handles which function the application should call
    
switch($_POST[filter]) {
        case 
"processForm":
            
processForm();
        break;
        default:
            
defaultForm();
        break;
    }
    
#/ End of Handling

?>
__________________
"I always wanted the adoration of John Lennon - With The Anonimity of Ringo Starr..."
QuizBay Help with the testing of this Beta site!
rolda hayes is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 12-03-2008, 08:24 AM Re: Some help with this please!
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
What would probably work is this:

Change $newLocation = VAR_UPLOAD_DIRECTORY.$fileName;
to $newLocation = VAR_UPLOAD_DIRECTORY.$_SESSION[LOGIN_NAME].'_'.$fileName;
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 12-03-2008, 08:44 AM Re: Some help with this please!
rolda hayes's Avatar
Wannabe Adventurer...

Posts: 642
Name: Darren
Location: England
No, uploads with the original filename ok but dosn't put the login name before it...

** EDIT **

Yep, got it working now, needed the ' ' around

$_SESSION['LOGIN_NAME'].

Cheers for you help Insensus
__________________
"I always wanted the adoration of John Lennon - With The Anonimity of Ringo Starr..."
QuizBay Help with the testing of this Beta site!

Last edited by rolda hayes : 12-03-2008 at 08:49 AM.
rolda hayes is offline
Reply With Quote
View Public Profile
 
Old 12-03-2008, 08:47 AM Re: Some help with this please!
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
I don't know in what variable the login name has been stored, but you kinda said it was in $_SESSION[LOGIN_NAME]. If it is in something else, you should replace $_SESSION[LOGIN_NAME] with the variable it is in, for the suggestion I made.
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 12-03-2008, 09:14 AM Re: Some help with this please!
rolda hayes's Avatar
Wannabe Adventurer...

Posts: 642
Name: Darren
Location: England
yeah it was my mistake in the original post! (TP added)

Another question... Would it be possible to have a confirmation email sent to me when the user uploads new images? posiibly containing their username in the email as well?
__________________
"I always wanted the adoration of John Lennon - With The Anonimity of Ringo Starr..."
QuizBay Help with the testing of this Beta site!
rolda hayes is offline
Reply With Quote
View Public Profile
 
Old 12-03-2008, 09:20 AM Re: Some help with this please!
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
You can use the mail() function for that purpose.
Exact details are on the following page: http://php.net/manual/en/function.mail.php

Often emails sent by this function land in your spam folder, but I've struggled with the problem for quite some time and I haven't found a good fix yet. :P
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Some help with this please!
 

Thread Tools

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

vB 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.10924 seconds with 12 queries