When upload same files or same name the script replace old file . How to skip new file if already exist. // Check if form has been submitted if(@$_POST['submit']){ ini_set("max_execution_time", 0); // no time-outs! ignore_user_abort(true); // Continue downloading even after user closes the browser. // URLS -- One on each line $URL = $_POST['url']; // Relative path to Save downloaded images // Default is "downloads" // Make sure that it is writable (chmoded correctly) $folder = $_POST['folder']; // Check if User has provided a local folder if (!$folder || !isset($folder)){ // Generate error if left blank by user. die ("Please specify local folder name"); } // Split all URLS into an array $urls = split("\n", $URL); // Remove Carriage Returns (useful for Windows-based browsers) $urls = str_replace("\r", "", $urls); $mh = curl_multi_init(); foreach ($urls as $i => $url) { $path = pathinfo($url); $g=$folder . "/" . $path["basename"] ; // Check if file already exists on local folder. if(file_exists($g)){ // If exists, delete the file so it always contains the latest update. unlink($g) or die("Unable to delete existing '$g'!"); } // Update the user of what's going on echo "$i) Downloading: from <b>$url</b> to <a href=\"$g\"><b>$g</b></a><br />"; if(!is_file($g)){ $conn[$i]=curl_init($url); $fp[$i]=fopen ($g, "w"); curl_setopt ($conn[$i], CURLOPT_FILE, $fp[$i]); curl_setopt ($conn[$i], CURLOPT_HEADER ,0); // curl_setopt($conn[$i],CURLOPT_CONNECTTIMEOUT,1000); curl_multi_add_handle ($mh,$conn[$i]); } } do { if (curl_multi_select($mh, 0.25) == -1) { usleep(170); } $n = curl_multi_exec($mh, $active); } while ($active); foreach ($urls as $i => $url) { curl_multi_remove_handle($mh,$conn[$i]); curl_close($conn[$i]); fclose ($fp[$i]); } curl_multi_close($mh); } // task closed PHP:
http://php.net/manual/en/function.file-exists.php You have this: if(file_exists($g)){ // If exists, delete the file so it always contains the latest update. unlink($g) or die("Unable to delete existing '$g'!"); } Code (php): So stop here instead of unlinking.