0

你能告诉我是否有办法用 php 上传图片而不用 chmoding 目录

ftp_site($conn_id, 'CHMOD 0777, /www/images/thumbs');

规避[function.move-uploaded-file]: failed to open stream: Permission...错误?

谢谢!

4

1 回答 1

4

绝对地。

我不确定你为什么使用 ftp_site()。您是将上传的文件通过 FTP 传输到另一台服务器,还是只是尝试制作一个上传表单以上传到提供 php 文件的同一台机器?

假设您正在上传到运行脚本的服务器,有几件事。确保您的 Web 服务器正在运行的用户(httpd、apache、lighttpd 或类似用户)对 $uploadPath 具有写入权限。为此,您可以对其进行 chmod 0777,但这是不安全的,因为系统上的任何用户现在都可以写入此文件夹,而我们只希望 apache 能够这样做。如果您需要帮助设置此部分,请通过http://yaauie.com/me与我联系;我不确定您在命令行中的舒适程度,并且不想用 jibberjabber 压倒您

这里有一些快速的程序代码,可以帮助你解决你被抓到的地方;将您的上传表单指向此脚本以进行测试。

<?php
// Set the upload path
$uploadPath = realpath('./images/thumbs/');

// test to see if the upload path is a directory that is writable
if(is_dir($uploadPath) && is_writable($uploadPath)) {

    // create the full path for the end result file
    $uploadFile = $uploadPath.basename($_FILES['userfile']['name']);

    // try to move the uploaded file
    if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadFile)) {
        echo 'Sucessfully moved file to "'.$uploadFile.'"';
    } else {
        echo 'Directory is writable, but we could not move the uploaded file to it.';
    }
} else {
    echo 'Either "'.$uploadPath.'" is not a directory, or it is not writable.';
}
?>
于 2009-03-11T04:07:54.437 回答