LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-14-2012, 06:52 AM   #1
luismartin
LQ Newbie
 
Registered: Mar 2012
Posts: 5

Rep: Reputation: Disabled
Problem with file permissions in PHP on Linux


I've implemented a code to sequentially copy, crop and resize an image to adjust it to a smaller size with different ratio.

Everything works correctly in the development server. However I have problems in the production server:

First of all, the code creates an exact copy of the file from the source to the destination. The copy works fine, and this is how it is created:

Code:
-rw-rw-rw- 1 www-data www-data 25256 2012-03-14 11:36 17-f07.jpg
Afterwards I added a chmod in order to give the image file total permissions

Code:
-rwxrwxrwx 1 www-data www-data 25256 2012-03-14 11:29 17-f07.jpg
The thing is that I can't edit the copied file once created, (with the same user www-data !! ). So there is an error when the code tries to crop or resize it subsequently.

Any help would be greatly appreciated.
 
Old 03-14-2012, 07:33 AM   #2
adixon
Member
 
Registered: Oct 2010
Posts: 34

Rep: Reputation: 3
Hey luismartin,
can you also post your php..
and are you creating a copy on server or elsewhere?
 
Old 03-14-2012, 07:51 AM   #3
luismartin
LQ Newbie
 
Registered: Mar 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by adixon View Post
Hey luismartin,
can you also post your php..
and are you creating a copy on server or elsewhere?
Hello adixon,

well the whole code involving this process would be too large, but this is a snippet:


PHP Code:
$source config_item('document_root') . $srcSrc;
$dest config_item('document_root') . $srcDest;
try {
    if (! 
$this->_process_image($source$sourceWidth$sourceHeight'90%'true'auto'false'thumb'$dest)) { // Make exact copy
        
throw new Exception("Error copying $source to $dest");
    }
    if (! @
chmod($dest0777)) {
        throw new 
Exception('File permissions error. File cannot be manipulated.');
    }
    if (! 
$this->_crop_image($dest$x_axis$y_axis$finalWidth'')) { // Crop image with the ratio obtained with the final dim
        
throw new Exception("Error cropping $dest");
    }
    if (! 
$this->_process_image($dest$destWidth$destHeight'90%'true$master_axisfalse'thumb'$dest)) { // Resize cropped image
        
throw new Exception("Error resizing cropped image $dest");
    }
}
catch(
Exception $e) {
    
$error $error "\n" $e->getMessage();

The error I get is:
"Error cropping /var/www/.../images/image_name.jpg"
 
Old 03-14-2012, 08:20 AM   #4
adixon
Member
 
Registered: Oct 2010
Posts: 34

Rep: Reputation: 3
what return code do you get from _crop_image?
also is it possible _process_image is not closing file resource appropriately..
 
Old 03-14-2012, 06:09 PM   #5
luismartin
LQ Newbie
 
Registered: Mar 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by adixon View Post
what return code do you get from _crop_image?
also is it possible _process_image is not closing file resource appropriately..
_crop_image returns true if the image is cropped, and false if there was a problem

I don't think _process_image is not closing the file resource properly. Both functions use a method of the CodeIgniter Image Manipulation class, which encapsulates everything. So it is not likely to be the problem...
 
Old 03-14-2012, 06:32 PM   #6
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
What are the ownership and permission of the folder containing the copied image?

(And why did you make the files +x? Not necessary.)
 
Old 03-14-2012, 08:00 PM   #7
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Why don't you try save the output image to different name and check if your production server has the same GD library as testing.
That way you could eliminate errors ...

easy php crop example and another.

Last edited by lithos; 03-14-2012 at 08:04 PM.
 
1 members found this post helpful.
Old 03-15-2012, 04:58 AM   #8
luismartin
LQ Newbie
 
Registered: Mar 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hello dive and lithos.

dive: This is the list line corresponding to the containing folder:

Code:
drwxrwxrwx  2 desarrollo desarrollo  4096 2012-03-14 13:31 novedades
It's owned by another user ("desarrollo") but all the premissions are granted to everyone. I also added +x just in case. I'm not good on Linux yet.

lithos: you've been very helpful. I've echoed the phpinfo from both the development and production server and while the first one has gd enabled, the second one doesn't specify anything about gd. So is it possible that it has nothing to do with premissions but with the GD library? If the gd library is not installed, why did the copy work?
 
Old 03-15-2012, 05:38 AM   #9
luismartin
LQ Newbie
 
Registered: Mar 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Bingo!

It was due to the GD library which was not installed in production. Just installed it and everything works!

Thanks a lot everyone!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with file permissions (C++ and PHP) fcdev Programming 1 02-01-2011 08:11 PM
MySQL/PHP/Apache application - file permissions rgriffiths Linux - Server 4 05-17-2009 03:20 AM
Permissions for file uploading script in php emab Programming 7 08-31-2008 06:53 AM
permissions on flat file php authentication blizunt7 Linux - Security 2 11-23-2005 06:13 AM
file permissions w/apache php caguru Linux - Newbie 3 04-26-2001 07:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration