-4

I'm trying already for two hours to understand what am I doing wrong and I can't figure it out:

My HTML code:

<form action="php/images.php" method="post" enctype="multipart/form-data">
    <input type="file" name="image" value="on"  id="file">
    <input type="submit" name="submit" value="Submit">
</form>

My PHP:

if ( isset($_POST['image'])
    && $_POST['image']=="on")
{
    imageUpload();
}

When I removed the if in the PHP file and immediately entered the inner function imageUpload() I've been able to upload the image, why is the variable name I pass using post isn't working?!

4

2 回答 2

4

您的上传数据将在$_FILES数组中:

<?php print_r($_FILES['image']); ?>

所以是这样的:

<?php 
if($_SERVER['REQUEST_METHOD'] === 'POST'){
    if(isset($_FILES['image']) && $_FILES['image']['error'] == 0){
        imageUpload();
    }
}
?>
于 2013-07-07T17:40:59.763 回答
1

browse button lets you make an array and can be obtain via $_FILES['image'];.Similarly $_FILES also gives an array(size etc).Try var_dump($_FILES); to get the values.

于 2013-07-07T17:45:00.067 回答