Jump to content

File ownership loop.


Warmics

Recommended Posts

This is probably a trivial task to most of you, but I can't for the life of me

figure out how to do this.

 

I want to write a script that will open an image directory, go through

each of the images inside and change their permissions, owner and group.

 

Thanks in advance.

Link to comment
Share on other sites

Thanks for the reply,

 

I wrote a PHP script to upload the images.

These images are getting uploaded as user: apache, group: apache.

I therefore can't edit them nor download them via my FTP client.

I was thinking the easiest thing to do was run a PHP script that

will modify these files as PHP scripts DO have access to them. They are a couple

hundred though, so doing this one by one would be extremely inefficient.

 

I'm not familiar with this thing about the shell, I'll do some research about it.

I've been teaching myself this stuff, so I have a lot of knowledge gaps here and

there.

 

I appreciate the time.

Link to comment
Share on other sites

i thought I needed to change ownership in order to download the images to my computer.

You see, the images are being uploaded from different computers via a very amateur CMS.

I noticed the person uploading the images is not making them small, so they are uploading

2 MB images (for thumbnails and stuff). I wanted to download all the images to my personal pc and shrink'em. But I can't

because my FTP Client tells me I have no access to them. I know how to change one by one using a simple PHP script, I was just

hoping there was a way to use a loop for this, but I'm not sure how to use PHP to do so.

 

Thanks again.

Link to comment
Share on other sites

No, you need to give the read permission to the user running your web server.

 

You probably need to give the directory/folder execute permission to the user running the web server as well, in order to iterate through the directory. I could be wrong about this though, I don't have a nix box handy to check at the moment.

Link to comment
Share on other sites

Ownership controls what you can do to something while permissions control what you can do with it. When the PHP script uploads the file, make it

chmod($filename, 0644);

the file. That should take care of not being able to download future files; for the existing files you can write a very quick script that does that chmod() on everything. It would look like

foreach (glob("/path/to/uploads/*.*") as $file) chmod($file, 0644);
// and that's all there is to it, really

 

Otherwise if you have a PHP script that can shrink one file, modify it so that it can shrink a series of files. Or easier, make a new script which sets up a couple variables as needed and then include()s the shrinking script.

 

But ultimately this problem should be solved in the CMS: when images are uploaded they should be resized if above a certain size (be that pixel dimensions or file size or whatever).

 

You probably need to give the directory/folder execute permission to the user running the web server as well, in order to iterate through the directory. I could be wrong about this though, I don't have a nix box handy to check at the moment.

Yes, that's required. Odds are this is one of two situations: either the files are world-not-readable (like 0600 or 0640) or the directory has world-not-executable (like 0700 or 0750). Or both. What's unusual is that this is quite rare to have set up by default. Normally files are naturally 0644 and directories 0755 and then something manually changes those permissions to be more restrictive.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.