Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

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;

        // ...

    }
}
share|improve this question

marked as duplicate by kapa, Superbest, Paul Richter, Matt Clark, Dave Zych Feb 21 at 20:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Could there be a conflict since you have named your file field with the same name as the id? –  Philip G Feb 21 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.. –  Adelphia Feb 21 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[]' –  Fred -ii- Feb 21 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. –  N.B. Feb 21 at 16:53
2  
Work through this check list: stackoverflow.com/a/3587158/930917 –  ɴ ᴀ ᴛ ʜ Feb 21 at 16:54

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
3  
@AlirezaFallah, he did do before he edited the post. Why on earth would I have made that up? –  Prisoner Feb 21 at 16:46
    
No he isn't? theres no slash at the end of tag! –  Philip G Feb 21 at 16:46
    
Yes I did before and realized that when I posted this, but I fixed it, and it's still broken. –  Adelphia Feb 21 at 16:46
1  
@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. –  Prisoner Feb 21 at 17:44
1  
@Adelphia Paid off showing full code ;-) It's the little things that count. ;-) –  Fred -ii- Feb 21 at 18:07

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.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.