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;

        // ...

    }
}
I wrestled a bear once.
  • 22,983
  • 19
  • 69
  • 116
  • Could there be a conflict since you have named your file field with the same name as the id? – Philip G Feb 21 '14 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.. – I wrestled a bear once. Feb 21 '14 at 16:45
  • What do you want from the file uploaded? –  Feb 21 '14 at 16:46
  • can you post the result of `var_dump($_FILES)` ?? – Alireza Fallah Feb 21 '14 at 16:47
  • I dont know, and don't think that schould be a reason for the files not beeing sent. But its bad practise and javascript surely doesn't like it! – Philip G Feb 21 '14 at 16:47
  • 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[]'` – Funk Forty Niner Feb 21 '14 at 16:48
  • I'd suggest turning on error reporting and checking server log. Maybe the file is too large or something. – Salman Feb 21 '14 at 16:48
  • @Fred-ii- no, it's not the full code. it's the code up until the error. anything after that is irrelevant. but it is the full code up until that point. – I wrestled a bear once. Feb 21 '14 at 16:50
  • *"I checked the post values and $_POST['file'] exists and contains the name of the file."* It's not `$_POST['file']` you should be checking, it's `$_FILES['file']` - where are you checking for `$_POST['file']`? I see you're checking `$_FILES` in your `var_dump()` but not anywhere else. – Funk Forty Niner Feb 21 '14 at 16:52
  • @AlirezaFallah `array(0) {}` – I wrestled a bear once. Feb 21 '14 at 16:52
  • Testing the code on my local PC shows the code working perfectly. So I guess there is something wrong in the script you are POST'ing to. – DescX Feb 21 '14 at 16:52
  • 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 '14 at 16:53
  • is `file_uploads = On;` in php.ini? – naththedeveloper Feb 21 '14 at 16:53
  • 2
    Work through this check list: http://stackoverflow.com/a/3587158/930917 – naththedeveloper Feb 21 '14 at 16:54
  • @N.B. The file I'm uploading is 11KB.. the default should suffice. It's not there because it's not necessary to change it. – I wrestled a bear once. Feb 21 '14 at 16:54
  • The only thing I can think of (without seeing full code), is that your file/folder and the ??? variable(s) are not properly set, or not set, or a typo. @Adelphia - I can't keep commenting like this (or anyone else for that matter), I'm terrible at shooting Black golf balls at midnight while aiming for a black hole. Remember, `$File` is not the same as `$file`. Good luck with that. – Funk Forty Niner Feb 21 '14 at 16:58
  • Thank you for your suggestions. I've done this 100 times before successfully. If it was an easy fix I wouldn't be asking for help :) – I wrestled a bear once. Feb 21 '14 at 17:02
  • I don't mind helping, but when I don't see the full picture, I can't be of further help. Nothing personal, that's just "me". ;-) – Funk Forty Niner Feb 21 '14 at 17:11
  • Thanks @Fred-ii- I'm getting desperate. Here's a pastebin with the entire code. http://pastebin.com/0rWNw6Jh – I wrestled a bear once. Feb 21 '14 at 17:20
  • Why do u have a self closed form? Other than invalid html that may be causing your issue, what's the use of an empty form? – CodeBird Feb 21 '14 at 17:35
  • in your `php_ini` check `file_upload` is on or not.. and also check `max_upload_size`... – Nishant Solanki Feb 21 '14 at 17:47
  • @Adelphia I noticed in your pastebin file `` notice the `z`? Think that might have anything to do with it? Shouldn't that be `` as you posted in your question, just without the `z`? – Funk Forty Niner Feb 21 '14 at 18:03

2 Answers2

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.

elitechief21
  • 2,964
  • 1
  • 17
  • 15
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.

Prisoner
  • 27,391
  • 11
  • 73
  • 102