doutu3352 2011-11-12 08:49
浏览 217
已采纳

表单提交后显示$ _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']?

<?php

if(isset($_POST['submit'])) {

 //preview page

$info = getimagesize($_FILES['image']['tmp_name']);
$imagetype = $info['mime'];
$tmpname = $_FILES['image']['tmp_name'];
$fp = fopen($tmpname,'r');
$data = fread($fp,filesize($tmpname));
$data = addslashes($data);
fclose($fp);

} else {
?>

<form enctype="multipart/form-data" action="http://www.example.com/submit" method="POST">
<input type="file" name="image" value="" size="50" />
<input type="submit" name="submit" value="submit" />
</form>

<?php
}

?>
  • 写回答

3条回答 默认 最新

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

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

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

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

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度