我是PHP新手,我使用此代码将图像从ftp下载到我的桌面:
// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
echo "<p> Connected as " . $ftp_user . " " . $ftp_server . "</p>";
} else {
echo "<p> Couldn't connect as" . $ftp_user . "</p>";
}
$local_file = "C:\Users\sam\Desktop";
$server_file = "ftp://md346645@188.93.148.30/public/sites/www.ronvanderwerf.com/Images/beeld.jpg";
// download server file
if (ftp_get( $conn_id, $local_file, $server_file, FTP_ASCII))
{
echo "Successfully written to $local_file.";
}
else
{
echo "Error downloading $server_file.";
}
我在XAMPP上运行此代码。不幸的是,这就是我得到的:
*Connected as md346645 188.93.148.30*
*Warning: ftp_get(C:\Users\sam\Desktop): failed to open stream: Permission denied in C:\xampp\htdocs\Website ron\index.php on line 34*
*Warning: ftp_get(): Error opening C:\Users\sam\Pictures in C:\xampp\htdocs\Website ron\index.php on line 34*
*Error downloading ...md346645@188.93.148.30/public/sites/www.ronvanderwerf.com/Images/beeld.jpg.*
在我看来,我必须通知chmod $local_file
给予许可。不幸的是,我没有成功实现这一点。
有没有人有任何想法?
答案 0 :(得分:1)
ftp_get函数的第二个参数是文件名,而不是目录。这段代码实际上是试图将图像保存到文件“C:\ Users \ sam \ Desktop”中,这当然不是一个文件,我想Windows不允许任何事情发生在这个珍贵的文件夹中......
您只需要添加正确的文件名,试试这个:
$local_file = "C:\Users\sam\Desktop\theimage.jpg";
或者,如果您希望将图像保存在当前文件夹中,只使用文件名:
$local_file = "theimage.jpg";