在PHP文件上传期间检查帖子属性[关闭]

Hi I have the following saved as upload.php.

<html>
<head>
</head>
<body>
    <?php
        for($file_count = 0; $file_count <= count($_FILES['files']['tmp_name']); $file_count++){
            echo '111111';
            if( $_FILES['files']['error'][$file_count] == 0){
                echo '2222222222';
                $target_dir = "uploads/".time().$_FILES['files']['name'][$file_count];
                echo '333333333333';
                move_uploaded_file($_FILES['files']['tmp_name'][$file_count], $target_dir);
                echo '4444444444444';
            }
        }
    ?>
    <div>
        <form method="post" name="upload_form" enctype="multipart/form-data"
            action="">
            <input type="file" name="files[]" enctype="form/multipart"> <input
                type="submit" id="photo_upload" value="Upload Photo...">
        </form>
        <div id="contents">fggfgfg</div>

    </div>
</body>
</html>

The upload works fine. The problem is when I launch the page, I see error messages. (Can't upload screenshots to show them).

To avoid them I tried checking if the form was set in the post request like so: if(isset($_POST[])).

But when I have the above if block, the code inside it does'nt get executed even when I select and submit the files.

How can I get around this.

QUESTION 2:

Can somebody please point me to jquery based file upload example? I have to asynchrously upload files since there are other form field available on the page.

You should give name attribute to your submit element change it to this

<input type="submit" id="photo_upload" name="Submit" value="Upload Photo...">

and then check like this

if(isset($_POST['Submit']))

Answer 1: you can check for post variable as well as with file object like

if(isset($_FILES)) 

or for using POST you have to assign name tag to your submit button

like

<input type="submit" id="photo_upload" name="Submit" value="Upload Photo...">

Answer 2 : for file upload with asynchrously you can use jquery file up loader you can check below live demo

it is very easy to use and customize as we need.