SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Sep 2004
    Location
    seattle
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question edit a record with file upload

    How do i make it so that when someone edits a recipe that already has a file upload it doesn't get overwritten?

    For instance if i have /recipes/uploads/potstickers when i edit the file it gets overwritten with /recipes/uploads/

    i can supply the code if it's necessary. Thanks in advance for you help!

  2. #2
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It would help if you posted your code.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  3. #3
    SitePoint Addict
    Join Date
    Sep 2004
    Location
    seattle
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here you go

    php:

    # path to save the file to
    $folder = "/home/www/littlesaigondenver.com/recipes/uploads";

    # get the original filename so it has the same name when saved
    $orig_filename = $_FILES['image']['name'];
    $dir = "/recipes/uploads";

    # get the temporary name of the file
    $image = $_FILES['image']['tmp_name'];

    # copy the temp file to the file directory
    copy($image, "$folder/$orig_filename");
    $msg="lo";
    $sql="update recipe set title='$title',instructions='$instructions',ingredients='$ingredients',contributor='$contributor',categoryid=$bgid,description='$description',servings='$servings',prep='$prep',image='$dir/$orig_filename' where recipeid=$id";
    $res=mysql_query($sql);
    }

    upload part of the form:

    <form method="post" name="myform" action="<? print $PHP_SELF; ?>" enctype="multipart/form-data" onsubmit="javascript: return checkifvalid();">
    <tr>
    <td>File to Upload/td>
    <td><input type="file" name="image" size=45 value"<? print $dir/$orig_filename; ?>"></td>
    </tr></form>

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    if you use the original row name pulled from the database eg: $row['image']; and echo that into the form input. At the moment you are echoing the original filename of the file being submitted.

    Alternatively you could give the user a seperate form for updating the image, something like, "do you wish to edit the picture?"...
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Addict
    Join Date
    Sep 2004
    Location
    seattle
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    works great. okay..got another issue. what if there isn't an image for a specific recipe? how do i set a default image of notavail.gif so that the user doesn't have to upload it? I tried to set it in the default for mysql, but once again it gets overwritten. This is when the user adds a new recipe.


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
  •