7

Yes, the enctype attribute is set. Other forms/form-hanlders work fine so the temp directory must be writable. I'm out of Ideas.

I checked the post values and $_POST['file'] exists and contains the name of the file.

Here is my form and the PHP that handles it. What am I missing?

<form action='orl_ftp.php' method='post' enctype='multipart/form-data'>
    <table>
        <tr>
            <td>Choose File: </td>
            <td><INPUT type='file' id='file' name='file'></td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td><INPUT type='submit' name='Submit' value='Process'></td>
        </tr>
    </table>
</form>

And the relevant PHP code. Note that the $_FILES array is set, it's just empty.

if(isset($_POST['Submit'])){
    $upload_results = "";
    if(!isset($_FILES)){$upload_results .= "No files uploaded"; }
    if($upload_results == ""){

        echo "<pre>";
        var_dump($_FILES);
        exit;

        // ...

    }
}
22
  • Could there be a conflict since you have named your file field with the same name as the id? Commented Feb 21, 2014 at 16:44
  • @PhilipG is that really a thing? Every file upload form I've ever built I just use file as both the name and id and it has always worked.. I'll try changing it tho, can't hurt.. Commented Feb 21, 2014 at 16:45
  • 2
    I'm not quite grasping the question here. If nothing is uploaded, then you can't expect it to show anything. I don't see move_uploaded_file anywhere, so this tells me this is not full code. To add, you say "array". When dealing with arrays, and if you are, then this name='file' needs brackets name='file[]' Commented Feb 21, 2014 at 16:48
  • 1
    PHP has variables that control maximum upload size. Your web server has configuration that limits the maximum request size. You haven't posted a single thing about those two. I suggest you google about that. Commented Feb 21, 2014 at 16:53
  • 2
    Work through this check list: stackoverflow.com/a/3587158/930917 Commented Feb 21, 2014 at 16:54

2 Answers 2

4

You have multiple forms in the same script and so each of them needs the enctype='multipart/form-data'

Also, it doesn't look like you close the first form and doing <form ... /> is not valid html.

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

1 Comment

This solved my problem, thanks! Basically if you have more than 1 form on the page, close them properly.
3

On line 101:

<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" />
                                                                 ^

This is causing the issue, the browser it keeping this form open and therefore the missing enctype is the issue. Remove or close this form properly.

Example:

<?php
if(isset($_POST['Submit'])){
    $upload_results = "";
    if(!isset($_FILES)){$upload_results .= "No files uploaded"; }
    if($upload_results == ""){
        echo "<pre>";
        var_dump($_FILES);
        exit;
    }
}
?>
<form action='' method="post" />
<form action='' method='post' enctype='multipart/form-data'>
    <table>
        <tr>
            <td>Choose File: </td>
            <td><INPUT type='file' id='file' name='file'></td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td><INPUT type='submit' name='Submit' value='Process'></td>
        </tr>
    </table>
</form>

This will not post any files.

7 Comments

@AlirezaFallah, he did do before he edited the post. Why on earth would I have made that up?
No he isn't? theres no slash at the end of tag!
Yes I did before and realized that when I posted this, but I fixed it, and it's still broken.
@Adelphia, i've un-deleted my question and corrected it. I was right initially, but just not the right line as you didn't post all of the relevant code.
@Adelphia Paid off showing full code ;-) It's the little things that count. ;-)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.