0

I am uploading a file to a server through an HTML form and then emailing the HTML form content to myself. I can store all the form values into PHP variables like this...

$name = strip_tags($_POST["name"]); 
$email = strip_tags($_POST["email"]);
$phone = strip_tags($_POST["phone"]);

but can not store the file name of the uploaded file in the same way. ex..

$uploadFile0 = strip_tags($_POST["uploadFile0"]);

I'm storing the file(s) to my server using a loop.

$i = 0;
    while(isset($_FILES['uploadFile'. $i])){
       echo 'item' . $i . 'present';
        $file_name = $_FILES['uploadFile'. $i]['name'];
        $file_name = stripslashes($file_name);
        $file_name = str_replace("'","",$file_name);
        $copy = copy($_FILES['uploadFile'. $i]['tmp_name'], $folderPath . $file_name);
        if($copy){
            echo "$file_name | uploaded sucessfully!<br>";
        }else{
            echo "$file_name | could not be uploaded!<br>";
        }
        $i++;
    };

Basically I want to capture the name of the file to a variable and echo it out in an email. I have a feeling I'm staring at the answer but I just can't put it together. Thanks in advance for the help!

2
  • isn't $file_name the name of the file? Commented Oct 4, 2011 at 15:30
  • Uploaded files in PHP NEVER appear in the _POST array. They're only in _FILES, so you'd want $_FILES['uploadFile']['name'] instead. Commented Oct 4, 2011 at 15:57

1 Answer 1

1

Will $_FILES['uploadFile'. $i]['name'] not give you the name of the file?

Or just to grab the first one $_FILES['uploadFile0']['name']

Sign up to request clarification or add additional context in comments.

1 Comment

That's it. I just had to create the variables like this $uploadFile0 = $_FILES['uploadFile0']['name']; $uploadFile1 = $_FILES['uploadFile1']['name']; $uploadFile2 = $_FILES['uploadFile2']['name'];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.