【问题标题】:cannot echo image-data in php, html无法在 php、html 中回显图像数据
【发布时间】:2016-10-31 12:13:16
【问题描述】:

我是 php 的菜鸟,我无法在 php 中显示图像数据。我尝试了 1 小时,但无法理解问题所在。请帮忙。

<?php
ini_set('mysql.connect_timeout',300);
ini_set('default_socket_timeout',300);
?>

    <form method="post" enctype="multipart/form-data">
    <br/>
        <input type="file" name="image"/>
        <br/><br/>
        <input type="submit" name="submit" value="Upload"/>
    </form>
    <?php
        if(isset($_POST['submit'])
        {
                   $imagedata=mysql_real_escape_string(file_get_contents($_FILES["image"],["tmp_name"]));
            echo $imagedata;
        }
        else
        {
            echo "there has been some error";
        }
    ?>

</body>

【问题讨论】:

  • 你这里有很多错误
  • stop using mysql_* functions These extensions 已在 PHP 7 中被删除。了解 PDO 和 @987654325 的 prepared 语句@ 并考虑使用 PDO,it's really pretty easy
  • 非常感谢,从现在开始我将在项目中使用 mysqli。我不知道 pdo 是什么,但我会用谷歌搜索它。再次感谢
  • @JohnConde 是的,我已经确定了他们。谢谢你:)

标签: php html


【解决方案1】:

固定代码:

<!DOCTYPE html>
<html>
    <head>
    </head>
<body>
    <form method="post" enctype="multipart/form-data">
        <input type="file" name="image">
        <input type="submit" name="submit" value="Upload">
    </form>
    <?php
        if(isset($_POST['submit'])) {
            $imagedata=file_get_contents($_FILES["image"]["tmp_name"]);
            echo $imagedata;
        } else {
            echo "there has been some error";
        }
    ?>
</body>
</html>

但是,这只会输出二进制数据。如果你想实际显示图像,你将不得不做更多的事情......

【讨论】:

  • 谢谢你,程序员:)
猜你喜欢
  • 2015-01-20
  • 2014-12-03
  • 1970-01-01
  • 2015-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-19
  • 2016-06-18
相关资源
最近更新 更多