doutu3352 2011-11-12 00:49
浏览 218
已采纳

表单提交后显示$ _FILES ['image']

How do i display the image uploaded after the form has been submitted? After the form is submitted it will be a preview page, so i'm not storing the image type BLOB in MySQLyet. How do i display $_FILES['image']?

  1. <?php
  2. if(isset($_POST['submit'])) {
  3. //preview page
  4. $info = getimagesize($_FILES['image']['tmp_name']);
  5. $imagetype = $info['mime'];
  6. $tmpname = $_FILES['image']['tmp_name'];
  7. $fp = fopen($tmpname,'r');
  8. $data = fread($fp,filesize($tmpname));
  9. $data = addslashes($data);
  10. fclose($fp);
  11. } else {
  12. ?>
  13. <form enctype="multipart/form-data" action="http://www.example.com/submit" method="POST">
  14. <input type="file" name="image" value="" size="50" />
  15. <input type="submit" name="submit" value="submit" />
  16. </form>
  17. <?php
  18. }
  19. ?>
  • 写回答

3条回答 默认 最新

  • dsyrdwdbo47282676 2011-11-12 01:31
    关注

    If you don't want to store the image on the server you can preview like this:

    1. <?php
    2. if (isset($_FILES['image'])) {
    3. $aExtraInfo = getimagesize($_FILES['image']['tmp_name']);
    4. $sImage = "data:" . $aExtraInfo["mime"] . ";base64," . base64_encode(file_get_contents($_FILES['image']['tmp_name']));
    5. echo '<p>The image has been uploaded successfully</p><p>Preview:</p><img src="' . $sImage . '" alt="Your Image" />;
    6. }

    But if you want to store it on the server, just store it and show it without changing the page.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部