I am using Scrapy to gather images. I would like to simulate a post onto a PHP script with multiple files. Similar to when someone uploads 10 files and they get processed by a PHP script using $_FILES['name']
. I would also like to pass $_POST
data as well.
Here is my Python.
post_array={
'parse':'listing'
}
files_array=response.xpath(root+'/photos//url/text()').extract()
returned=requests.post(php-script.php,data=post_array,files=files_array).text
pprint(returned)
So this is suppose to create a $_POST
variable and a $_FILES
variable with multiple files. How can I convert the list of URLs in files_array to become a $_FILES
array in the php-script.php?
Python data input:
post_array={
'parse':'listing'
}
files_array=['https://example.co/123.jpg','https://example.co/124.jpg','https://example.co/125.jpg']]
into PHP data output inside php-script.php (desired result):
$_POST=['parse'=>'listing'];
$_FILES=['images'=>[
[0] => Array
(
[name] => 123.jpg
[type] => image/jpeg
[tmp_name] => /tmp/php/php6hst32
[error] =>
[size] => 98174
)
[1] => Array
(
[name] => 124.jpg
[type] => image/jpeg
[tmp_name] => /tmp/php/php6hst32
[error] =>
[size] => 98174
)
[2] => Array
(
[name] => 125.jpg
[type] => image/jpeg
[tmp_name] => /tmp/php/php6hst32
[error] =>
[size] => 98174
)
]];
I have also tried this:
returned=requests.post(triggers,data=post_array,files={'images':[url for url in files_array requests.get(url).content]}).text
pprint(returned)