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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.