Jump to content

changing an uploaded files name


envexlabs

Recommended Posts

here is my upload function:

function upload_image($upload_dir, $store_pic_id){
    //sets the directory and name for the file
    $uploaddir = 'uploads/'. $upload_dir .'/';
    $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
    
    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) 
    {   
        echo('<h2>Congratulations</h2>');
        echo("Your file has been uploaded!<br /><br />");
        echo('<img src="uploads/' . $upload_dir . '/'. $_FILES[userfile][name] . '" />');
        echo('<br /><br /><a href="profile.php">Back to Profile</a>');
    } 
    else {
        echo "Possible file upload attack!\n";
    }
    
    [color=blue]//puts the array into a variable so that it can be inputed into the database as a name.ext instead of Array[]
    $name = $_FILES[userfile][name];[/color]
    
    //updates the table with the new avatar image
    //$query = "UPDATE `t_info` SET `av` = '$name' WHERE ID = '$ID'";
    //$result = mysql_query($query) or die(mysql_error());
    
    //changes the permissions of the file
    chmod('uploads/'. $upload_dir .'/' . $name . '', 0644);
}

 

If i change the blue text to say, $name = 'test'; i get errors.

 

I want to set the image name to a members ID number. how would i achieve this?

 

Thanks,

 

envex

Link to comment
https://forums.phpfreaks.com/topic/57424-changing-an-uploaded-files-name/
Share on other sites

hey,

 

sorry, i forgot to input the error, trying to do 5 things at once :P

 

Warning: chmod() [function.chmod]: No such file or directory in /mnt/gs02/herd02/20143/domains/werehavingasale.com/html/inc/php_functions.php on line 204

 

i'm going to play around, i dont think it's a name change error anymore.

 

will update soon.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.