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(), "
";
}
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.
use
file_get_contents($_FILES["myfile"]["tmp_name"]);
instead of
file_get_contents($_FILES["image"]["tmp_name"]);
since <input type='file' name='myfile'/>
better ref from Changing the file name of a tmp file uploaded through a form
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']);
}