#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    USA
    Posts
    226
    Rep Power
    15

    alterning filename during upload


    Can someone point me in the right direction? I have a directory on our site where we can upload images from the browser. Our application uses the images to construct client presentations. All images are stored in the same directory. We have had problems with people overwriting images. They upload images with the same name as images already in the directory. In order to prevent this, we need to make sure each image has a unique name. Well, the images are associated with a unique record in our database. Is there anyway to append the ID of the database record to the end of the image when uploading it. In other words can I change its name during upload?

    Example: Some one uploads an image named myimage.jpg into the images directory. Can I change this from myimage.jpg to myimage_181.jpg while it is uploading?

    If this is possible, can you point me to an explanation on how it is done.

    Thank you for your help.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    21
    Rep Power
    0

    Same Question


    THANK YOU IN ADVANCE

    I have the same question. Here's the code I am using to upload the files.
    <!--- PHP Portion Named uploads.php --->
    <?php $updir = images;
    if(!file_exists("$updir/$pic_name"))
    { copy($pic, "$updir" . "/" . $pic_name); }
    else { echo "File already exists!"; } ?>
    ------------------------------------------------------------
    This works Perfect, but the only thing is, If I have two users come and upload files which are named the same it will echo file already exists.

    So PART 2, To solve this problem I would like to append a unique identifier like a user name. The form portion code which is named upload.html is:
    ----------------------------------------------------
    <form enctype="multipart/form-data" action="http://www.mydomain.us/members/upload.php" method="post"> <input name="pic" type="file" size="20"></td> <input type="submit" value="Upload" name="upload">

    -------------------------------------------------

    So MY QUESTION:
    How TO and IS IT POSSIBLE to add a form field in this same form above but make it username and when the user clicks on upload it will upload the image but add the username they entered into the form so such instead of when they upload arrow.gif it will be username_arrow.gif

    Then Give us a way to call the same file they uploaded in the upload.html file in a page called my items.html

    ------------------------------------IDEA of what I am Trying to Do-----
    I have a domain and have members in that domain. So the members website address is mydomain.com/theirusername

    Now I added a image folder in the member folder so the form sends the image to the one folder that all my members share.
    The reason why they are uploading images is for their Products Page.
    The Products page will have THEIR image with product Description, and Price. I want their image to be called and displayed on this page. I would like to put something like

    <?=$row['product']?>

    for the image and ONLY the owner's image appears.

    Just like bramsey just added some so when you so graciously answers his/her question you will be so kind to include mine.

    Thanks you in advance
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    USA
    Posts
    226
    Rep Power
    15

    problem solved


    Here is what I ended up doing in asp.net. I don't know how much this will help you in php. Basically I am capturing the filename and stripping the extension off. Then I take what is left and add a unique id to it and replace the extension.

    Dim intFileCntr As System.Int32
    Try
    For intFileCntr = 0 To colFiles.Count - 1

    Dim objCurrentFile As System.Web.HttpPostedFile = colFiles(intFileCntr)
    Dim strCurrentFileName, strCurrentFileName2, strCurrentFileExtension As System.String

    strCurrentFileName = System.IO.Path.GetFileName(objCurrentFile.FileName)
    strCurrentFileName2 = System.IO.Path.GetFileNameWithoutExtension(objCurrentFile.FileName)

    strCurrentFileName = Right(strCurrentFileName, 3)

    If strCurrentFileName <> "" Then
    strCurrentFileExtension = System.IO.Path.GetExtension(strCurrentFileName)
    objCurrentFile.SaveAs("d:\webs\mysite.com\www\clientspace\images\concept\" + strCurrentFileName2 + "_" + Session("MainID").ToString + "." + strCurrentFilename)
    End If
    Next

    Catch Ex As Exception
    Response.Write(ex.message)
    End Try
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    21
    Rep Power
    0

    Dont know ASP


    I am sorry but I don't know asp and have never used it. So all of the information you listed above looks totally greek to me. I would like it if someone was just as thorough as you were but list the solution using PHP.

    Thanks for your help, I'll check back in a few for another answer.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    USA
    Posts
    226
    Rep Power
    15
    You may get more responses if you post this in the php forum instead of the .net forum.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    21
    Rep Power
    0

    oops


    I thought I did, sorry
    A dead give away to let you know I am a newbie
    I'll repost in the correct form

IMN logo majestic logo threadwatch logo seochat tools logo