SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jan 2002
    Location
    Waltham Abbey, Essex, UK
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Upload and display images

    If someone could help I'd be very greatful.

    I have a mysql database with a column called "photo"
    I have managed to write the php to upload an image into a flat file in my root directory and from here place to url of the image into the "photo" column of the db. My problem now is retrieving the image and displaying it.

    My code is as follows; (This is from Kevins book by the way)
    Image upload file:
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body bgcolor="#FFFFFF" text="#000000">
    <form action="fileupload.php" method="post" enctype="multipart/form-data">
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
    <p>Select file to upload: <input type="file" name="uploadedfile" /></p>

    <p><input type="submit" name="submit" value="Upload" />
    </p>
    </form>
    </body>
    </html>

    This refers to a php file:

    PHP Code:
    <!-- fileupload.php -->
    <?php
    $username 
    "johneeeee";
        if (
    $uploadedfile_type == "image/pjpeg"
        
    or $uploadedfile_type == "image/gif") {
         
    //Handle the file...
        
    }else{
         echo (
    "<p>Please submit a JPEG or GIF image " 
        
    "file.</p>\n");
         exit();
        }
        
    // Pick a file extension
        
    if ( "image/pjpeg" == $uploadedfile_type $extension ".jpg";
        else 
    $extension ".gif";
        
        
    // The complete path/filename
        
    $filename "C:/uploads/" time() . $REMOTE_HOST $extension;
        
        
    // Copy the file (if it is deemed safe)
        
    if (is_uploaded_file($uploadedfile) &&
        
    copy($uploadedfile$filename)) {
        echo(
    "<p>File stored successfully as $filename.</p>");
        }else{
        echo (
    "<p>Could not save file as $filename!</p>");
        exit();
        }
        
    $dbcnx mysql_connect("localhost""root""*****");
        if (!
    dbcnx) {
            echo (
    "<p>Unable to connect to database server at this time!</p>");
            exit();
            }
         
    mysql_select_db("dbName",$dbcnx);
         if (! @
    mysql_select_db("dbName") ) {
             echo (
    "Unable to locate the dbName database at this time.</p>");
            exit();
            }
         
         
    $sql "update name_address  
                 set photo='
    $filename'        
                WHERE username = '
    $username'  ";
            if (@
    mysql_query($sql)) {
                echo(
    "<p>$filename successfully placed in database.</p>");
                }else{
                echo(
    "<p>Error adding $filename to database!</p>");
                }
                
                
            
    "SELECT photo FROM name_address WHERE username = '$username'";

        
        echo 
    "<img src=$photo>";
    ?>
    Everything goes well until I try to retrieve the file location from the database. Nothing happens just a blank space. I've spent about 8 hours trying to solve this so it's not as if I haven't tried!

    Well that's it, if you can help please do.
    John

  2. #2
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you uploading the file itself into the database or just the path? Try using echo to print out the field containing the "image" or "path". See what you get, then you can go from there.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  3. #3
    SitePoint Member
    Join Date
    Jan 2002
    Location
    Waltham Abbey, Essex, UK
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm just loading the Path.
    I have tried using echo. To no avail. Hence my post.
    John


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •