-5

i am a noob in php i cant display the image data in php. im trying it for 1hr but cannot understand the problem. please help.

<?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>

  • 1
    You have numerous mistakes here – John Conde Oct 31 '16 at 12:14
  • ***Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).*** [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Oct 31 '16 at 12:17
  • Thank you very much i'll use mysqli in projects from now. i dont know what pdo is but i'll google it. thanks again – RadicalOne Oct 31 '16 at 14:32
  • @JohnConde yes i've identified them. thank you :) – RadicalOne Oct 31 '16 at 14:37

1 Answers1

0

Fixed code:

<!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>

However, this will just put out the binary data. If you want to actually show the image, you will have to do quite a bit more...

junkfoodjunkie
  • 3,168
  • 1
  • 19
  • 33