It's gives 404 Not Found While downloading file from url. i want to downloads file from url links.
i am tried with curl in PHP.
$output_filename = "text.jpg";
$imageUrl = "https://m.media-amazon.com/images/M/MV5BZjZhYTkyMjgtNjFkZi00NDAyLTk5ZDgtMDYwZTBkYTI1ODllXkEyXkFqcGdeQXVyNTc5OTMwOTQ@._V1_.jpg";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $imageUrl);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, false);
curl_setopt($ch, CURLOPT_REFERER, "http://www.xcontest.org");
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$result = curl_exec($ch);
curl_close($ch);
print_r($result); // prints the contents of the collected file before writing..
// the following lines write the contents to a file in the same directory (provided permissions etc)
$fp = fopen($output_filename, 'w');
fwrite($fp, $result);
fclose($fp);
When i runs script it returns me 404 not found warning for file not found. i also try to found solution from internet but not getting exact result. i think it gives warning due to downloading file from regular expression url link.
file is exist while paste image url in browser as show below image.