<?php
function saveFile($url, $filename) {
$data = file_get_contents($url);
$fh = fopen($filename, 'w') or die("can't open file");
fwrite($fh, $data);
fclose($fh);
}
$myFile = "images.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
$data = explode("n", $theData);
$count = count($data);
for($i=0;$i<=$count;$i++) {
saveFile($data[$i], basename($data[$i]));
}
?>
这是我的代码,每次我替换一个动态文件名,它打印错误
Warning: fopen(10017226314.jpg ) [function.fopen]: failed to open stream: Invalid argument in C:xampphtdocsdownloaddownload.php on line 4
can't open file
原因是什么?请帮助。由于
请将fopen函数参数从w
替换为r+
function saveFile($url, $filename) {
$data = file_get_contents($url);
$fh = **fopen($filename, 'r+')** or die("can't open file");
fwrite($fh, $data);
fclose($fh);
}