Reputation: 5883
I am using PHP to upload a file. The upload seems to be successful. The $_FILES array is:
Array ( [image] => Array ( [name] => mount.jpg [type] => image/jpeg [tmp_name] => /tmp/php61qYZj [error] => 0 [size] => 28947 ) )
Everything seems to be in order. However, when I do
echo '<img src="' . $_FILES['image']['tmp_name'] . '" />';
it gives me a broken image.
This is so basic, how can it possibly be failing?
Upvotes: 0
Views: 1845
Reputation: 779
You need to move uploaded file to your image folder and then you can use this image to display in your browser.
Example
move_uploaded_file($_FILES['image']['tmp_name'],'/public_html/images/'.$_FILES['image']['name']))
the above code will upload your file to images directory then you can use this image.
for ajax file upload please contact me.
Upvotes: 0
Reputation: 868
You are trying to show a picture that has been saved in /tmp
. You should move the file to a directory inside of the root of your web page.
Also see: Tutorial on PHP-based file uploading
Upvotes: 1
Reputation: 255005
$_FILES['image']['tmp_name']
is a temporary storage and works for only one request. It is not available from web as long as it usually located at OS directory for temporary files /tmp
. You need to move the file to some permanent storage which is available form web.
Upvotes: 2