Zend框架图像上传错误:给定的目标不可写


Zend Framework Image upload Error : The given destination is not writeable

//Default Image with article
    $imgElement = new Zend_Form_Element_File('imgElement');
    $imgElement->setLabel("Upload an Image:");
    $imgElement->setDestination(APPLICATION_PATH."/../upload/articleImg/");      
    $imgElement->addValidator('Count',false,1); //ensure only 1 file
    $imgElement->addValidator('Size',false,102400); //limit to 100K
    $imgElement->addValidator('Extension',false,'jpg,png,gif');
    $this->addElement($imgElement);

以上是我与文章一起上传文件的代码。我得到的错误是

An error occurred
Application error
Exception information:
Message: The given destination is not writeable

如果我做一个ls -l,我会得到drwxrwxr-x 3 aman aman 4096 Jul 31 20:03 upload 我有权写信给那个目录。如果我使用终端和 mv 一些文件到该位置,它会通过。我认为我的应用程序可能无权写入该目录?

这是一个错误还是什么?我也试过这个。但没有奏效

//Default Image with article
    $destination = APPLICATION_PATH."/../upload/articleImg";
    chmod($destination ,0777);
    $imgElement = new Zend_Form_Element_File('imgElement');
    $imgElement->setLabel("Upload an Image:");
    $imgElement->setDestination($destination);      
    $imgElement->addValidator('Count',false,1); //ensure only 1 file
    $imgElement->addValidator('Size',false,102400); //limit to 100K
    $imgElement->addValidator('Extension',false,'jpg,png,gif');
    $this->addElement($imgElement);

在托管控制面板中,您需要为该文件夹设置文件权限,使其可写。

转到控制面板的文件资源管理器并在那里进行更改。

-或-

如果是本地副本,则需要通过操作系统设置权限。

在Unix,Linux,Mac中,这是:

chmod 777 ./upload

(从公共/图像/文件夹中(

在窗口中,我认为您只需右键单击上传文件夹 ->属性并取消勾选只读。要么设置,要么在共享和安全选项中设置权限。

您的 Web 服务器可能未在上传文件夹上设置了写入权限的用户或组aman下运行。更改文件夹的所有者(www-data 在 ubuntu 上是默认的(

chown -R www-data ./upload

或授予其全局写入权限

chmod -R 777 ./upload

我会推荐第一个解决方案。该-R是可选的,如果需要,还会更改对upload文件夹的子文件夹的权限。

使用此链接解决:https://serversforhackers.com/permissions-users/

显然,我必须授予网络用户的访问权限,即www-data。已按照以下步骤操作。

sudo usermod -a -G www-data aman
sudo chgrp www-data /home/aman/Work/aman_proj
chmod g+rwxs /home/aman/Work/aman_proj

谢谢你们的帮助:)