Results 1 to 9 of 9

Thread: Link to display uploaded image(s)

  1. #1
    Join Date
    Dec 2010
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Link to display uploaded image(s)

    Hi all,

    Need help on displaying image that I have uploaded. The user uploads scan images into a specific user session folder.

    The user submits some requests to an approver and the approver vets the details along side with a link display the uploaded images.

    So far I have been able to upload the image file but my biggest problem is providing the link to display the uploaded images.

    Your help is welcome.

    The upload code is as follows;

    PHP Code:
    <?php 
    session_start
    ();
     
    //require_once("../admin/db.php");

    // define a constant for the maximum upload size
    define('MAX_FILE_SIZE'51200);
    if (
    array_key_exists('upload'$_POST)){
    // define constant for upload folder
    define('UPLOAD_DIR''C:/upload_test/');
    // replace any space in original filename with underscores
    // at the same time, assign to a simpler variable
    $file str_replace(' ''_'$_FILES['image']['name']);
    // convert the maximum size to KB
    $max number_format(MAX_FILE_SIZE/10241).'KB';
    // create an array of permitted MIME types
    $permitted = array('image/gif''image/jpeg''image/pjpeg''image/png','application/pdf');
    // begin by assuming the file is unacceptable
    $sizeOK false;
    $typeOK false;

    // check that file is within the permitted size
    if($_FILES['image']['size'] > && $_FILES['image']['size'] <= MAX_FILE_SIZE){
        
    $sizeOK true;
        }

    // check that the file is of a permitted MIME type
    foreach ($permitted as $type) {
    if(
    $type == $_FILES['image']['type']){
        
    $typeOK true;
        break;
        }
    }

    if (
    $sizeOK && $typeOK){
        switch(
    $_FILES['image']['error']){
        case 
    0:
            
    // $username would normally come from a session variable
            
    $username $_SESSION['username'];;
            
    // if the subfolder does not exist yet, create it
            
    if (!is_dir(UPLOAD_DIR.$username)){
                
    mkdir(UPLOAD_DIR.$username);
            }
            
    // make sure file of same name does not already exist
            
    if (!file_exists(UPLOAD_DIR.$username.'/'.$file)){
            
    // move the file to the upload folder and rename it
            
    $success move_uploaded_file($_FILES['image']['tmp_name'], UPLOAD_DIR.$username.'/'.$file);
            }
            else {
            
    // get the date and time
            
    ini_set('date.timezone''Europe/London');
            
    $now date('Y-m-d-His');
            
    $success move_uploaded_file($_FILES['image']['tmp_name'], UPLOAD_DIR.$username.'/'.$now.$file);
            }
            if(
    $success){
            
    $result "$file uploaded successfully";
            }
            else {
            
    $result "Error uploading $file. Please try again.";
            }
            break;
            case 
    3:
                
    $result "Error uploading $file. Please try again.";
            default:
                
    $result "System error uploading $file. Contact webmaster.";
            }
        }
        elseif (
    $_FILES['image']['error'] == 4) {
            
    $result 'No file selected';
            }
        else {
            
    $result "$file cannot be uploaded. Maximum size: $max. Acceptable file type: gif, jpg, png, pdf.";
            }
    }
    ?>
    Regards.

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Is C:/upload_test/ web accessible?
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Jan 2011
    Posts
    50
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    hi there..

    you're problem is getting the link of the uploaded images right?...have you tried trapping it in a way that when the images are uploaded, you assign a variable to hold the url so that when neede, you can call the variable..instead of calling the whole link...

  4. #4
    Join Date
    Dec 2010
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by bluewalrus View Post
    Is C:/upload_test/ web accessible?
    Yes its accessible

  5. #5
    Join Date
    Dec 2010
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by cindylou View Post
    hi there..

    you're problem is getting the link of the uploaded images right?...have you tried trapping it in a way that when the images are uploaded, you assign a variable to hold the url so that when neede, you can call the variable..instead of calling the whole link...
    I have not done any, Can you help me out?

  6. #6
    Join Date
    Jan 2011
    Posts
    50
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    i can't actually give you the exact lines of the script if i don't code it myself... but maybe this site might help you..

    http://php.net/manual/en/language.variables.php


  7. #7
    Join Date
    Dec 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile I need

    Hey guys i need anwers or question for final year student of SS3 in Nigeria ..if you get any leads please reply to this thread.

  8. #8
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    No idea what you're talking about Sarutobi sensei.
    Corrections to my coding/thoughts welcome.

  9. #9
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    The easiest way to get around this problem is to save the files in somewhere more accessible. For example:

    PHP Code:
    define('UPLOAD_DIR''/your_upload_dir'/); 
    This way you can actually access the file in a link like so:

    Code:
    <a href="/your_upload_dir/filename.jpg">Link to file</a>
    If you really do want to keep using the absolute path of C:/..., you could make a file that handles the opening of uploaded files, but it gets a bit more complex.

    Easiest thing to do is move the upload directory.

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
  •