Php: image display problem

Discussion in 'PHP' started by rafi, May 19, 2010.

  1. #1
    <html>
    <body>
    <form action="uploading.php" method="post" enctype="multipart/form-data">
    <table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
    <tr>
    <td width="246">
    <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
    <input name="userfile" type="file" id="userfile">
    </td>
    <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    <?php
    if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
    $con=mysql_connect("localhost" ,"root" ,"");
    mysql_select_db("rafi");
    {
    $fileName = $_FILES['userfile']['name'];
    $tmpName = $_FILES['userfile']['tmp_name'];
    $fileSize = $_FILES['userfile']['size'];
    $fileType = $_FILES['userfile']['type'];


    if(!get_magic_quotes_gpc())
    {
    $fileName = addslashes(file_get_contents($userfile));
    }

    $query = "INSERT INTO upload (name, size, type, content ) "."VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

    mysql_query($query)
    mysql_close($con);
    $query=("Select * FROM upload");
    $blah=mysql_query($query)
    while(list(*)=mysql_fetch_array($blah))
    echo "FileName";
    ?>
    THe image is not displaying plz help me !
     
    rafi, May 19, 2010 IP
  2. mike.judd

    mike.judd Greenhorn

    Messages:
    84
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #2
    You forget to move the image to some defined location as well as store the path into the database. Normally, I would use defined my path, then try to move my file over that path. If the file exist, give errors. Otherwise, use function move_uploaded_file and then store the path into database.
     
    mike.judd, May 19, 2010 IP
  3. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #3
    check where your script is uploading the images, make sure that you display the right path. and thats it
     
    bartolay13, May 19, 2010 IP
  4. abstractworld

    abstractworld Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You have not moved the images from temp to some physical location of your server. You can use move_uploaded_file php function to move the image to a defined location.and keep that path in DB.
     
    abstractworld, May 19, 2010 IP
  5. hadinih

    hadinih Member

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    You can try look the error message on your apache error.log or you can add :

    
    error_reporting(E_ALL);
    
    Code (markup):
    to show the error that occured
     
    hadinih, May 21, 2010 IP