Jump to content

File Upload rename file based on another form input


thaidomizil

Recommended Posts

Hello,

 

i'm trying to create some file upload which renames the files automatically, the renamed file name needs to be the value from another text field, example:

 

i have a file upload form, and a last name text input, after the file upload the file should be renamed to the value of the last name input.

 

i really don't know where to start here, can anyone give me some hint / advice?

 

Thanks.

Do you have any working code for the file upload process at all? What you are asking for would be a highly trivial task with working code, so I assume not. There are countless "PHP Upload" tutorials on the next. Go find one and create an upload page. You should be able to easily figure out the rename part since you have to name the file when you save it anyway. Post back with any problems you have.

 

If you just want someone to build it for you then you can post in the freelance forum.

move_uploaded_file

 

The line above "move_uploaded_file" get the name from the textbox named "last_name".

<?php
$uploads_dir = '/uploads';
foreach ($_FILES["pictures"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
        $name = $_POST['last_name'];
        move_uploaded_file($tmp_name, "$uploads_dir/$name");
    }
}
?>

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.