Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macintosh PHP file upload system, need help customizing it

    I am fairly new to PHP scripting and have come across a little problem. I am creating a file upload system so users can upload there owns photo's. I have got the following script but i need help in customizing it to fit my needs

    uploader.php
    Code:
    <?php
     
    // Where the file is going to be placed 
    $target_path = "uploads/";
     
    /* Add the original filename to our target path.  
    Result is "uploads/filename.extension" */
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
    $_FILES['uploadedfile']['tmp_name'];  
     
    $target_path = "uploads/";
     
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
     
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
        " has been uploaded";
         require_once('generate.php');
    } else{
        echo "There was an error uploading the file, please try again!";
    }
     
    ?>
    <br /><br />
    <a href="photogallery.php">Click Here to View Your Photo</a>
    generate.php
    Code:
    <?php
    $target_path = "uploads/";
     
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
     
        $pfile = fopen("userpics.htm","a+");
     
          // If everything is OK -> store user data
       
            fwrite($pfile, "\n<embed src = \"$target_path\" /><p>");
    fclose($pfile);
    ?>
    photos.php (where the user sees the uploaded photo)
    Code:
    <?php
    include("userpics.htm");
    ?>
    I need help to define how the image will look. I need to know how i can get the php code to add a CSS style to the photo and if possible for it to use the lightbox javascript action. The lightbox isn't exactly essential as long as i can link to a full size image but it would be nice. Also the CSS script would shrink the photo for the thumbnail. I just need to link to a full size image.

    I hope that you can understand this and that you can help me out cos it is really getting on my nerves now. I have tried everything i can think of

    Thanks

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    You should upload both a fullsize and a thumbnail image,
    along with a caption. Those would be selected in a form.

    Right after you upload your photo to a directory,
    append a line to a text file that has the photo filename and caption.
    It can also have some sort of ID, like a timestamp (for sorting or future editing).

    That text file called "gallery.txt" might look something like this:

    12341241|myphoto1.jpg|myphoto1_thumbnail.jpg|This is my first photo
    34235254|myphoto2.jpg|myphoto2_thumbnail.jpg|My Vacation photo

    Now, the script that generates the images can open that
    text file and read each line one by one ... it then generates
    the HTML to do whatever you want with the image.

    PHP script that displays gallery:
    PHP Code:
    #Read File List
    $database="gallery.txt";
    $fp fopen($database"r");
    $array1 explode("\n"fread($fpfilesize($database))); 
    fclose ($fp);
    sort($array1);# rsort=reverse sort

    $count count($array1);
    for(
    $i 0$i $count$i++) {
    list (
    $id$photo$full$thumb$caption) = split ('\|'$array1[$i]);

    // Now you echo the HTML, and it could be Lightbox code too ...
    echo"
    <a href='$full'><img src='$thumb' alt='' /></a>
    "
    ;



  •  

    Posting Permissions

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