This is an URL that points to an image:
I get the image if I use cURL as this command in CLI:
/usr/bin/curl -o 1234.jpg 'the_url_to_image'
I need to use cURL in PHP with arguments. I tried several parameters to get the image, and I always get a 403 error
Access to the specified resource has been forbidden. Apache Tomcat
My parameters (only the cURL parameters, the code for writting the image to file is not here):
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $img_url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, false);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie_filename);
curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_filename);
$page_content = curl_exec($ch);
curl_close($ch);
EDIT
If I feed the image URL to this page:
onlinecurl.com
I get the image binary back, and no the error message.
So the image can be saved with cURL, I only need to get the curl_setopt
settings right.
EDIT
By running the a command in CLI the image is saved to the local path
/usr/bin/curl -o 1234.jpg 'the_url_to_image'
When running the same command with
shell_exec("/usr/bin/curl -o 1234.jpg 'the_url_to_image'")
The error message is saved in the 1234.jpg file.
What can be the difference in the command line and code execution of the same command?