Page 1 of 1

Change file name

Posted: Mon Feb 16, 2004 7:16 pm
by S_henry
I want to upload my picture and change that file (picture) name same as my login. This mean everybody can upload their picture when they login into my system and the picture will be saved in 1 folder. Let say my picture's file name is 'johnphillip' and my login is 'john'. So I want to save this picture using 'john' as a name in that folder after uploaded. Any idea pls...

Posted: Mon Feb 16, 2004 7:39 pm
by DuFF
Do you already have an upload script and authentication (or at least the Username held in a cookie/session)?? If so all you need to add is a few lines, other wise you should start with the upload form first and we'll help you from there.

Change file name

Posted: Mon Feb 16, 2004 7:53 pm
by S_henry
Ok. Let me do session part first and then we'll continue. I'll be back..

Change file name

Posted: Tue Feb 24, 2004 12:00 am
by S_henry
Ok. I've create a session and can hold the login and password value to any page. After that, what should I do?

Change file name

Posted: Tue Feb 24, 2004 2:17 am
by S_henry
Anybody can help me pls...

Change file name

Posted: Wed Feb 25, 2004 3:01 am
by S_henry
Maybe too difficult I think, at least for me... :(

Posted: Wed Feb 25, 2004 4:02 am
by malcolmboston
simplest way i would do it
psuedo-code wrote: create a session with your username appended to it

go to your 'upload area'

run an if/else statement to see if a var has been set
rename the file using $username

Posted: Mon Mar 01, 2004 2:11 am
by S_henry
Actually I not very understand how to do it. Can anybody explain pls.. Thanx.

Try this

Posted: Mon Mar 01, 2004 2:35 am
by andre_c
Try something like this:
- An upload form:

Code: Select all

<form action="formhandler.php" enctype="multipart/form-data" method="post">

    <input type='file' name='loginpic' />

    <input type='submit' name='imgupload' value='Send Picture' />

</form>
- Form Handler Page:

Code: Select all

<?
if (isset($_REQUEST['imgupload'])) {
    $pic_dir_name = '/path/to/image/'.$_SESSION['login_name'].'.jpg';

    if (is_uploaded_file($_FILES['loginpic']['tmp_name'])) {
        copy($_FILES['loginpic']['tmp_name'], $pic_dir_name);
    } else {
        echo "Image Upload Failed. Filename: " . $_FILES['loginpic']['name'];
    }
}
?>