Image Upload/ 99% there....

Discussion in 'PHP' started by dannbkk, May 29, 2007.

  1. #1
    I have this code on my index.php page where i want the image to show;

    index.php
    and i have this where im trying to upload the image from;

    cms-events.php

    At the moment its working perfectly, and the file is uploading to my ftp server under /files folder but the image is not displaying on my index.php page?

    When i than go to the database to check all fields have been entered apart from the image field? is this why? does it also need to go the database before it can be viewed on the index.php page? or do i have to add an extra line of code for the image to display on the index.php page...
     
    dannbkk, May 29, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Change:
    $image = $_POST['image'];
    PHP:
    To:
    $image = $_FILES['imagefile']['name'];
    PHP:
    Also, the code for uploading file should be combined with the PHP code for collating POST data for SQL query.

    One last thing:
    if(isset( $Submit ))
    PHP:
    That should never be used as it relies on register_globals. Even if you are not distributing scripts, it is a good habit to use the proper method, in this case: $_POST['Submit']
     
    krt, May 30, 2007 IP
  3. dannbkk

    dannbkk Well-Known Member

    Messages:
    1,403
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    120
    #3
    thankyou, i have actually solved my problem i had.
     
    dannbkk, Jun 1, 2007 IP
  4. ndreamer

    ndreamer Guest

    Messages:
    339
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg"){ //<--- Note the type (check the change below and post the error)
    
    Code (markup):
    note that $_FILES['imagefile']['type'] is sent by the browser you should not use this to validate the file type, to correctly validate look in to

    mime_content_type (deprecated)
    PECL extension Fileinfo
    or you can use something like this (from php.net documentation)

    if ( ! function_exists ( 'mime_content_type ' ) )
    {
       function mime_content_type ( $f )
       {
           return trim ( exec ('file -bi ' . escapeshellarg ( $f ) ) ) ;
       }
    }
    Code (markup):
     
    ndreamer, Jun 1, 2007 IP