0

I'm trying to move the pictures to a new folder called new_images, but move_uploaded_file isn't working. I tried copy($entry, $dir2); that isn't working either. It's on a live site. Any suggestions?

$dir = $_SERVER['DOCUMENT_ROOT'].'/images/classifieds/'.$row['user_id'].'/ads/'.$row['listbingo_ad_id'].'';

if ($handle = opendir($dir)) {
    //echo "Directory handle: $handle\n";
    //echo "Entries:\n";

    /* This is the correct way to loop over the directory. */
    while (false !== ($entry = readdir($handle))) {

        if($entry !="." && $entry !=".."){

           $dir2 = $_SERVER['DOCUMENT_ROOT'].'/images/new_images/'.$entry;

           move_uploaded_file($entry, $dir2);
           echo "INSERT INTO tbl_classified_image (clsd_id,mem_id,cls_img_file,img_status) VALUES(".$row['listbingo_ad_id'].",6,'".$entry."','Y');\n";

        }
    }

}
hakre
  • 193,403
  • 52
  • 435
  • 836
  • Does `move_uploaded_file` issue a warning? http://www.php.net/manual/en/function.move-uploaded-file.php#refsect1-function.move-uploaded-file-returnvalues – faintsignal Apr 07 '14 at 00:44
  • Nope .. it doesn't.. weird – user3495710 Apr 07 '14 at 00:46
  • 1
    `move_uploaded_file()` is not for copying file around on your file system. It is for moveing files that are in the process of being uploaded ($_FILE). Use `copy()` or `rename()`. http://stackoverflow.com/questions/19139434/php-move-a-file-into-a-different-folder-on-the-server – RiggsFolly Apr 07 '14 at 00:55
  • Copy doesn't work either ...var_dump(copy($image, $dir2)); It returns true but the folder has no images – user3495710 Apr 07 '14 at 00:57
  • Nevermind , it worked , I had to refresh the folder in filezilla – user3495710 Apr 07 '14 at 01:01

0 Answers0