PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, March 2, 2022

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

 March 02, 2022     file-upload, lamp, php, zend-form, zend-framework     No comments   

Issue

//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);

Above is my code to upload a file along with the article. The error I get is

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

If I do an ls -l , I get drwxrwxr-x 3 aman aman 4096 Jul 31 20:03 upload I have permission to write to that dir. If I use terminal and mv some file to that location it goes through. I think my application might not have the access to write to that dir maybe ?

Is this a bug or something ? I tried this too. But didn't work

//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);

Solution

Solved using this link : https://serversforhackers.com/permissions-users/

Apparently I had to grant the access to the web user i.e. www-data. Followed the steps below.

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

Thanks for help guys :)



Answered By - Aman
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing