简体   繁体   中英

Get an image in php using the <img src=“” tag

<html>
<form action="image_test.php" enctype="multipart/form-data" method="post">
    <table style="border-collapse: collapse; font: 12px Tahoma;" border="1" cellspacing="5" cellpadding="5">
        <tbody>
            <tr>
                <td><img src="digital.jpg" name="image1"></td>
            </tr>
            <tr>
                <td><input name="Upload Now" type="submit" value="Upload Image"></td>
            </tr>
        </tbody>
    </table>
</form>
<html>
<?php
header('Content-type: image/jpg');
print "<pre>".print_r($_FILES,1)."</pre>";
$file=$_FILES['image1']['tmp_name'];
?>

How do I retrieve the image in php to then upload it later. This is important as I am getting the image from my webcam

您可以将摄像头捕获的图像绘制到画布中 ,然后使用getImageData方法通过ajax将画布图像数据发送到PHP服务器。

I could not understand what you are doing here , first you create an html form ok then you start a session and sending Content type header, that is complelety stupid, header must be send first, other wise you can face "Header all ready send Error", then the main thing is that you set the content type to image/jpg but seding html data, :o ?

I think what you want is :

you want that tag image on server, but it seems that file is already on server ? Oo ,, or it may be any other server ?

If it is one the same server then you can do like this :-

 <td>
   <img src="digital.jpg" name="image1">
   <input type="hidden" name="file_location" value="digital.jpg">
</td>

Then you can check on server like this :-

if(isset($_GET['file_location'])){

   if(file_exists($_GET['file_location'])){

        // process on image
        // if image is remote, then you can use file_get_contents('') { remote must be allowed in php.ini } 

   }  // exists

} // 

And Last line :- It is completely stupid Code and you must find other way to solve your problem :) ,, Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM