I am trying to test a scraping setup targeting sites of my own using servers of my own, but when I do I get an error from WPRobot saying "Error: Inserting post failed. Cannot create attachment file in "/home/myapp/public_html/wp-content/uploads/2021/03/162153879_434009211024473_384527521975744737_n.jpg" Please set correct permissions." I typically get this notice if the source does not allow other sites to copy its content using curl requests. To get around this I setup a Puppeteer script to act as a proxy by taking screenshots of image files on the source website (in this case Instagram), but now I get the same error when trying to download the screenshots from my own IIS server.
I have added nothing to my server that is intended to prevent anyone from being able to curl image files from it. In fact, there are several sites that were hosted on the same server recently. WPRobot never had a problem downloading any images from those. I have changed nothing other than uploading a Node.js application to the default website directory after deleting the old websites for the purpose of using this server to test the app before my account with the host is suspended in a few days.
What would cause images on an IIS 10 server to not be accessible via curl on the default website? Here is an example image for which WPRobot claims correct permissions are not set http://85.17.219.113/images/2021/3/505648a2-3404-c3e6-618f0fa50fd3.jpg? Could this be due to using an IP address instead of a domain name? Could the length of the file name be an issue?
Also: the image is only 92kb in size. I mention this because I have had issues with WPRobot displaying the same error when trying to download large files, but this file is nowhere near large enough to trigger that.
UPDATE: This appears to be a problem with file_get_contents and/or file_put_contents in PHP and NOT curl. For instance, the following results in an error:
$page = file_get_contents('http://85.17.219.113/images/2021/3/505648a2-3404-c3e6-618f0fa50fd3.jpg'); try{ file_put_contents('test.jpg', file_get_contents($page)); echo 'file downloaded'; }catch(Exception $e) { echo 'Message: ' .$e->getMessage(); } That code does not create a file and does not echo an error message either, but when I turned on error reporting I got this:
Fatal error: Uncaught ValueError: file_get_contents(): Argument #1 ($filename) must not contain any null bytes in C:\xampp\apps\wordpress\htdocs\sources\test.php:16 Stack trace: #0 C:\xampp\apps\wordpress\htdocs\sources\test.php(16): file_get_contents('\xFF\xD8\xFF\xE0\x00\x10JFIF\x00\x01\x01\x00\x00...') #1 {main} thrown in C:\xampp\apps\wordpress\htdocs\sources\test.php on line 16 I cannot explain this error. How can that URL translate to a filename with null bytes?
This downloads the image just fine:
$url = 'http://85.17.219.113/images/2021/3/505648a2-3404-c3e6-618f0fa50fd3.jpg'; // Image path $img = 'test.jpg'; // Save image $ch = curl_init($url); $fp = fopen($img, 'wb'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); Now I need to find the function in WPRobot that is used to cache images and save them to the file system. Does anyone know where that function is in WPRobot? It would be nice to know exactly how that plugin saves images.
https://stackoverflow.com/questions/66728143/wprobot-cannot-copy-images-from-iis-server March 21, 2021 at 09:50AM
没有评论:
发表评论