move_uploaded_file function

Discussion in 'PHP' started by sp360, Jul 24, 2008.

  1. #1
    ok, im using the move_uploaded_file function to sore the images in a directory on my server when the user uploads the pictures. But, at the same time, i want that picture to be saved in a diffrent directory as well. So here is the original code
    file_exists(DIR "files/$img.jpg") ) {
    					if (is_uploaded_file($files['Users']['pic']['tmp_name'])) {
    						move_uploaded_file($files['User']['pic']['tmp_name'], DIR "files/$img.jpg");
    PHP:
    and now, i want the same picture thats beeing uploaded to be saved in files/backup so here is what I tried:
    file_exists(DIR "files/$img.jpg") ) {
    					if (is_uploaded_file($files['Users']['pic']['tmp_name'])) {
    						move_uploaded_file($files['User']['pic']['tmp_name'], DIR "files/backup/$img.jpg");
                            move_uploaded_file($files['User']['pic']['tmp_name'], DIR "files/backup/$img.jpg");
    PHP:
    the files are uploading fine to the "files" directory but not uploading to the "files/backup" directoy. Any help?
    Thanks, SP360
     
    sp360, Jul 24, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    In is_uploaded_file() and move_uploaded_file(), you're using two different variables. I guess it's a typo. $files['Users'], and $files['User'].

    Also, in your second code, you're attempting to move the same file twice to the same location? Use move_uploaded_file() once to move the file to the main folder, and then use copy() to create a backup in a diffent folder.
     
    nico_swd, Jul 25, 2008 IP
  3. lamborevijay

    lamborevijay Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It seems u r uploading both the files in same folder. Plz. chk. the move_uploaded_file() in both statements.
     
    lamborevijay, Jul 25, 2008 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    I wish I would have thought of that.
     
    nico_swd, Jul 25, 2008 IP