SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict Volitics's Avatar
    Join Date
    Aug 2003
    Location
    US
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Append Text At End Of Existing Text On Same Line

    I'm working on a part of my web site that uploads images, then writes the name of the image to a text file.

    The upload part works fine. The part that writes the name of the image to the text file works fine.

    What I'm trying to do is, after all the files have been uploaded and all of the image names have been written to the WriteTo.txt file, append a written description of the picture at the end of the picture name.

    In other words, after a user uploads their pictures to the server I want to direct them to a page where they can label each of the pictures using a form.
    PHP Code:
    // ---- Code snippet, part of a loop that uploads files
    // ---- Loops through and uploads files one at a time. This part is working fine.
    if (copy ($TempName"$Admin[Directory]/$FileName")) {
        if (
    $Open fopen ("$Admin[Directory]/WriteTo.txt""a")) {
        
    flock ($Open2);
        
    fwrite ($Open$FileName."\t\n"); // Writes the file name to WriteTo.txt
        
    flock ($Open3);
        
    fclose ($Open);         
            }    
    }else{
    echo 
    "bla, bla, bla";
    }

    // ---- WriteTo.txt - above snippet prints to file like so:
    PictureOne.gif
    PictureTwo
    .gif
    PictureThree
    .gif
    PictureFour
    .gif
    PictureFive
    .gif

    // ---- Here's what I'm trying to figure out.
    // ---- I need to append a string to the end(s) of the picture names like this:
    PictureOne.gif        Picture of Aunt Betty.
    PictureTwo.gif         Picture of Uncle Fred.
    PictureThree.gif    Picture of boat.
    PictureFour.gif        Picture of motorcycle.
    PictureFive.gif        Picture of maple tree
    I would appreciate any suggestions that anyone might provide.

    Thanks.

    Volitics
    .

  2. #2
    o_O O_o BlueFire2k5's Avatar
    Join Date
    Mar 2003
    Location
    Sioux Falls, SD
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you want this in the text file, or in the actual filename?

  3. #3
    SitePoint Addict Volitics's Avatar
    Join Date
    Aug 2003
    Location
    US
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The above needs to appear in the text file.

    I've got the first part working (only partly shown). The first part inserts the names of the images, i.e. PictureOne.gif, PictureTwo,gif, etc., in line item format - like so:

    PictureOne.gif
    PictureTwo.gif
    PictureThree.gif
    PictureFour.gif
    PictureFive.gif


    The first part is working okay.

    Actually, I need to do a couple of more things. First, I need to write a script that will append the description of each of the images on the same line as the image name and to the right of the image name like so:

    //-------------------Need script to append the below.
    PictureOne.gif..... tab ....Picture of Aunt Betty.
    PictureTwo.gif..... tab ....Picture of Uncle Fred.
    PictureThree.gif..... tab ....Picture of boat.
    PictureFour.gif..... tab ....Picture of motorcycle.
    PictureFive.gif..... tab ....Picture of maple tree.


    Then, I need to write another script that will extract the whole thing and display the pictures or images in the browser along with the description of the picture.

    In other words, the first part of the line needs to be extracted and inserted into the "<img src=\"PictureOne.gif\">" string. The last part of the line needs to be extracted and inserted below the picture.

    I'm looking at the manual now to see if I can figure out some things but I don't have them figured out yet..

    Thanks.

    Volitics
    .

  4. #4
    SitePoint Addict
    Join Date
    Dec 2002
    Location
    Gent, Belgium, Europe, World, Univers
    Posts
    397
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't append into textfiles.

    however, the easiest way is to read all your images into an array (the image name that is) and display those in a form, then loop the array and rewrite the file from scratch with the filename AND the description.

    That way, there is no appending needed and you still have all your image names.

  5. #5
    SitePoint Addict Volitics's Avatar
    Join Date
    Aug 2003
    Location
    US
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    kajakske;

    Thank you for your kind response.

    That's exactly what I was beginning to think. From looking at the manual I did not see any file functions that would do what I want.

    Instead, what I'm doing is is reading the whole thing into an array - something like this:

    $Array[ ] = "<input type="hidden" name="FileName><input type="text" name="Description>";

    and then on the next page have a loop whereby it loops though each line and then writes it to the file. I think that I need a "for" loop or something.

    What I'm wondering is, after I get the picture name(s) and description(s) on one line, when I go to extract the whole thing and output the results on the browser page, can I break the line into two parts, insert the first part into an image source link (i.e. <img src=\"PictureOne.gif\"> and then insert the second part into a description under the picture?

    I'm not to that point just yet - but would I need to use a substring function to extract the two parts?

    Thanks.

    Volitics
    .


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
  •