//Start a couple of counters $c = 0; $e = 0; //Open the file as an array $file = file( 'attachment.txt' ); //Loop through the file contents. This assumes the file HAS contents. foreach( $file as $dl ) { //Trim the URL of any excess whitespace $url = trim( $dl ); //Line up a path for the file to go locally $img = './files/' . basename( trim( $dl ) ); //Try to move the file $put = file_put_contents( $img, file_get_contents( $url ) ); //Success, add to the counter if( $put ) { $c++; } //Fail, add to the counter and let the user know which file failed else { echo "
Unable to download: " . $dl . "
"; $e++; } } //Last success output echo "