简体   繁体   English

PHP ftp_get权限被拒绝

[英]PHP ftp_get Permission denied

Im new in PHP and I'm using this code to download a image from a ftp to my Desktop: 我是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.";
}

I am running this code on XAMPP. 我正在XAMPP上运行此代码。 Unfortunately, this is what I get: 不幸的是,这是我得到的:

*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.*

It seems to me that I have to chmod my $local_file to give permission. 在我看来,我必须chmod $local_file给予许可。 Unfortunately I did not succeed to accomplish that. 不幸的是,我没有成功做到这一点。

Does anyone have any ideas? 有人有什么想法吗?

The second parameter of the ftp_get function is a file name, not a directory. ftp_get函数的第二个参数是文件名,而不是目录。 This code is actually trying to save the image into the file "C:\\Users\\sam\\Desktop", which is of course not a file and I guess Windows doesn't allow anything to happen to this precious folder... 此代码实际上是试图将图像保存到文件“ C:\\ Users \\ sam \\ Desktop”中,该文件当然不是文件,我想Windows不允许对此珍贵的文件夹进行任何操作...

You just have to add the correct filename, try this : 您只需要添加正确的文件名,请尝试以下操作:

$local_file = "C:\Users\sam\Desktop\theimage.jpg";

or, with only the filename if you want the image to be saved in the current folder : 或者,如果要将图像保存在当前文件夹中,则仅使用文件名:

$local_file = "theimage.jpg";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM