setting the file field dynamically

Discussion in 'PHP' started by beermaker74, Jan 21, 2007.

  1. #1
    hello
    I hope that I have an easy question. I have a page that allows images and captions to be uploaded. The images get uploaded and the image names get inserted into my database. It then transfers them to a display page. On this page you can see the images you just uploaded plus the captions. I have set up the page to let users update the captions and images. This is where my problem is. I have the images being dynamically displayed, Then I have the image upload file field just below the image. Plus the caption field below that. I have 5 image fields. So if I browse and upload on one of the file fields, it sets all the other images to blank. So if the user wants to update any of the images, they have to update all of them or it doesnt work. So I thought I could just set the file fields data binded to the url I have in the recordset. So if they only change one photo field then that would be the only one that changes. I inserted the value from the bindings panel in design view in dreamweaver. It looks like it is set but it doesnt seem to work. Here is an example of the file field code

    <label for="image2">File 2:</label>
    <input name="image[]" type="file" id="image2" value="<?php echo $row_Recordset1['photo2url']; ?>" />

    So if there is any way to set this value it would make my life a whole lot better. If this is not the way I should go about this task. Then please let me know. MY main goal is to let the user manage photos for a real estate listing that are stored in a folder unique to that listing.
    thanks
     
    beermaker74, Jan 21, 2007 IP
  2. projectshifter

    projectshifter Peon

    Messages:
    394
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Your description is kind of confusing. Why not just do a catch to make sure the field is not empty, in which case leave it alone? Doing a file field means it's going to pull from a local folder on the user's PC, so inserting a name into it automatically is bad, but I don't think you can set value="" on it since it could easily be abused if I had a hidden one that got something from your window's drive or so.
     
    projectshifter, Jan 21, 2007 IP
  3. beermaker74

    beermaker74 Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    ok if i cant set the file field value then this is what I am trying to do. I have set up a variable above my sql update statement. I am then going to insert this variable into my statement. What I want to do is write an if else statement to test if the image file field has any data in it. ie they browsed to a new image and want to change the one they have. So if (file field 1 is blank) then $photo1url = my recordset photo1url. else $photo1url = $_FILES['image']['name']['1'];
    how do i test to see if the file field is empty? Does this make sense? AmI creating too much work for myself. Forgive me if I am going about this issue in a convoluted way. I am stiil learning php
     
    beermaker74, Jan 21, 2007 IP
  4. projectshifter

    projectshifter Peon

    Messages:
    394
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    To test if a field is empty, use if (!$_FILES['image']['tmp_name'][1]) By the way, try not to use ['1'] because 1 is an integer, not a string. You do realize that 0 is the first one as well correct?
     
    projectshifter, Jan 21, 2007 IP
  5. beermaker74

    beermaker74 Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    worked like a champ
    on to the next problem now. Search engine friendly urls
     
    beermaker74, Jan 22, 2007 IP
  6. projectshifter

    projectshifter Peon

    Messages:
    394
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    mod_rewrite is your friend
    RewriteEngine On
    RewriteRule ^([0-9]+)_(.*).html$ view.php?id=$1 [NC,L]

    a couple lines from my stuff, but basically it will take anything that is like 253_Man-Flips-Car.html and pushes it to view.php?id=253. That way they look like html files, you still pass the id# like you would in most cases, but they look fun and inviting and search engines eat them up like cracker jacks. Cheers
     
    projectshifter, Jan 22, 2007 IP