我对PHP脚本还很陌生,我还找不到满足我愿望的答案,所以我希望有人能告诉我如何做到这一点。
我收到一个对php文件的$_POST请求,其中包含一些数据
stock_nr=1&manufacturer=Audi&model=A1&images=http%3A%2F%2Fimages0.wheeler.nl%2Fs1386081049%2F6911582-1-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081072%2F6911582-2-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081102%2F6911582-3-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081131%2F6911582-4-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081161%2F6911582-5-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081192%2F6911582-6-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081227%2F6911582-7-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081255%2F6911582-8-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081280%2F6911582-9-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081313%2F6911582-10-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081341%2F6911582-11-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081368%2F6911582-12-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081398%2F6911582-13-2-2.jpg
我制作了一个文件来声明这样的变量:
$stock_nr=$_POST['stock_nr'] ;
$manufacturer=$_POST['manufacturer'] ;
$model=$_POST['model'] ;
$images=$_POST['images'] ;
如何获取发布在变量中的图像链接数量?
编辑:这就是我想要做的,而且效果很好。
这就是我想做的,它做了它应该做的:
function process_images() {
$images = explode(',', $_POST['images']);
foreach($images as $image_nr => $image_url) {
$filename = 'images/'. $_POST['stock_nr'] .'-'. $image_nr .'.jpg';
$imgdata = file_get_contents($image_url);
file_put_contents($filename, $imgdata);
}
}
这些链接用","分隔,您只需要对其进行explode()即可。
$images=explode(',',$_POST['images']);
print_r($images);