图片上传被拒绝的权限

时间:2012-07-17 21:22:14

标签: php file-upload permissions file-permissions image-uploading

我正在尝试从用户接收图像,然后将其上传到我的Amazon S3帐户,但我从Zend Framework收到错误Warning: move_uploaded_file(/items) [function.move-uploaded-file]: failed to open stream: Permission denied。我通过FTP将文件夹的权限设置为777,但我仍然收到错误。这是产生错误的代码,它有可能产生差异。我会假设接收错误。我怎样才能摆脱这个错误?

$upload = new Zend_File_Transfer();
        $upload->addValidator('ImageSize', false, array('minwidth'  => 100,
                                                  'maxwidth'  => 1000,
                                                  'minheight' => 100,
                                                  'maxheight' => 1000), 'image')
         ->addValidator('Extension', false, 'jpg')
         ->addValidator('Count', false, array('min'=>0, 'max'=>2));

if($upload->isUploaded('image')){ //Pic was uploaded
                if($upload->isValid('image')){ //Pic is valid
                    echo "Pic provided is valid.";
                    $upload->addFilter('Rename',array('target'=>"/items/{$item_id}_nla.jpg",'overwrite'=>true));
                    $upload->receive();
                    $pic = "/items/{$item_id}_nla.jpg";
                    $s3->putObject("media.completeset.com/images/items/{$item_id}_nla.jpg", $pic,
                                    array(Zend_Service_Amazon_S3::S3_ACL_HEADER => Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ,
                                          Zend_Service_Amazon_S3::S3_CONTENT_TYPE_HEADER => "image/jpeg"));
                    echo "Pic is uploaded.";
                }
                echo "Pic is invalid.";
            }

1 个答案:

答案 0 :(得分:2)

更改目录,使其成为绝对目录:

$projectRootDirectory = "/var/www/myproject";
// ...
$upload->addFilter('Rename',array('target'=> $projectRootDirectory."/items/{$item_id}_nla.jpg",'overwrite'=>true));
// ...
$pic = $projectRootDirectory."/items/{$item_id}_nla.jpg";

如果您已经在项目根目录中,请删除第一个/