1

I have written the following code. Nothing is written in the web browser and no error is thrown. Can anyone please help me to identify the problem?

try {
   echo file_get_contents($_FILES["image"]["tmp_name"]);
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}

Here is the form:

echo "<form action='upload.php' method='post' enctype='multipart/form-data'> 
        <p><input type='file' name='myfile'/></p>
        <p><input type='submit' value='Upload'/></p>
        </form>";

The thing was that I was following a tutorial where I was supposed to set: $image=file_get_contents($_FILES["image"]["tmp_name"]); When the person in the tutorial tried to echo it the files content was written in the browser. Nothing happened for me. I assume it is not working.

4

1 回答 1

5

利用

  file_get_contents($_FILES["myfile"]["tmp_name"]); 

代替

  file_get_contents($_FILES["image"]["tmp_name"]);

since <input type='file' name='myfile'/>

更好的参考更改通过表单上传的 tmp 文件的文件名

if($_SERVER['REQUEST_METHOD']=='POST' && isset($username) && is_numeric($id)
&& isset($_FILES['myfile']['error']) && $_FILES['myfile']['error']=='UPLOAD_ERR_OK')
{
    $name    = basename($_FILES['myfile']['name']);
    $ext     = end(explode('.', $name));
    $info    = getimagesize($_FILES['myfile']['tmp_name']);

}
于 2013-09-07T16:32:30.113 回答