By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,141 Members | 1,266 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,141 IT Pros & Developers. It's quick & easy.

Deleting Image Files from CMS

P: n/a
Hi there,

I have built a CMS, and in one part you have to be able to
delete images. Structure like this:

_root --> folder "img" --> file "1.jpg"
--> file "2.jpg"

--> folder "CMS" --> file "edit_text.php"
--> file "delete_img.php" (function 'unlink()' in it)

When i run "delete_img.php" it only works when i manually CHmod everything
0777 with an FTP-program.

Of course, that's not what i want when i have a CMS, and i don't want to leave
the "img"-folder CHmodded 0777, but after deleting the image i want it 0755
again...
And now the problem: chmod("../img/", 0777); doesn't work :(
I get the following error:

"Warning: chmod(): Operation not permitted in PATH"

Is there an alternative for unlink, or a way to get the CHmod to work..?

Thanks to all!
Jul 17 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
ph********@hotmail.com (phpfrizzle) writes:
I have built a CMS, and in one part you have to be able to
delete images. Structure like this:

When i run "delete_img.php" it only works when i manually CHmod everything
0777 with an FTP-program.

And now the problem: chmod("../img/", 0777); doesn't work :(
I get the following error:

"Warning: chmod(): Operation not permitted in PATH"


This error happens because the UID of the webserver process is not
owner of those files/dirs or root.

Well, who created those files and directories in the first place?
File perms and in general, ownership not relevant on deletion (unlink)
in Unix. This is Unix isn't it? It';s the directory permission bits
that matter since unlinking a file means makeing changes to a
directory.

Assuming your PHP code is being run by mod_php, the directories that
the images reside in must be writeable to the UID the webserver
process runs as.

Study up on owner and group access privs and go from there.

Quick solution probably to make the image dirs group writeable to
Apache. 0775 means read, write, search to owner read write, search to
group and read, search to world.

Figure out your GID of webserver by either looking in httpd.conf,
seeing it in a PS listing, seeing it in /etc/passwd etc.

HTH
--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/
Jul 17 '05 #2

P: n/a
Hi there,

Me again, i took Jerry's advice, and tried the USER settings etc., but
i still have the same problem. Even when i checked all nine the checkboxes
and other combinations....

Or am i searching in the wrong place?
I have Plesk 7. When i admin my files, there are a few variables for each
file/dir:

... Owner Group Permissions ...
name psacln rwx r-x r-x
But as i told you, permissions didn't work :(
I noticed i have the same problem with moving uploaded files....

Any help would be greatly appreaciated

Jerry Sievers <je***@jerrysievers.com> wrote in message news:<m3************@prod01.jerrysievers.com>...
ph********@hotmail.com (phpfrizzle) writes:
I have built a CMS, and in one part you have to be able to
delete images. Structure like this:

When i run "delete_img.php" it only works when i manually CHmod everything
0777 with an FTP-program.

And now the problem: chmod("../img/", 0777); doesn't work :(
I get the following error:

"Warning: chmod(): Operation not permitted in PATH"


This error happens because the UID of the webserver process is not
owner of those files/dirs or root.

Well, who created those files and directories in the first place?
File perms and in general, ownership not relevant on deletion (unlink)
in Unix. This is Unix isn't it? It';s the directory permission bits
that matter since unlinking a file means makeing changes to a
directory.

Assuming your PHP code is being run by mod_php, the directories that
the images reside in must be writeable to the UID the webserver
process runs as.

Study up on owner and group access privs and go from there.

Quick solution probably to make the image dirs group writeable to
Apache. 0775 means read, write, search to owner read write, search to
group and read, search to world.

Figure out your GID of webserver by either looking in httpd.conf,
seeing it in a PS listing, seeing it in /etc/passwd etc.

HTH

Jul 17 '05 #3

P: n/a
ph********@hotmail.com (phpfrizzle) writes:
Hi there,

Me again, i took Jerry's advice, and tried the USER settings etc., but
i still have the same problem. Even when i checked all nine the checkboxes
and other combinations....

Or am i searching in the wrong place?
I have Plesk 7. When i admin my files, there are a few variables for each
file/dir:

... Owner Group Permissions ...
name psacln rwx r-x r-x


What is this a file or dir? If it's a dir and isn't owned by the UID
that webserver runs as, the webserver isn't going to be able to delete
files from there.

--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/
Jul 17 '05 #4

P: n/a
Hi there again, thanks for taking the effort to read this.

It was a dir. I managed to get the upload script to work 'right'.
The file is uploaded, renamed & moved. And the file even gets CHmodded! :D
Executing script and it's folder are both set 'rwx rwx r-x'.

BUT... :-(
It only seems to work when i set the images dir-permissions to
'rwx rwx rwx' (0777) instead of 'rwx rwx r-x' (0755). So that's my first
question: is this dangereous, should it be different?

And my second:
The file uploaded has uid & gid 'apache' instead of the uid/gid
i'm running the upload script from. I tried the following:
chown ( "../img/$id.jpg", "uid"); // correct uid
chgrp ( "../img/$id.jpg", "gid"); // correct gid

But that just gives me errors. :(
Warning: chown(): Operation not permitted
Warning: chgrp(): Operation not permitted

CHmod works though....
So how do i change them to the right settings?

I am new to this uid/gid stuff, so please be gentle... ;)

Greetings

Jerry Sievers <je***@jerrysievers.com> wrote in message news:<m3************@prod01.jerrysievers.com>...

What is this a file or dir? If it's a dir and isn't owned by the UID
that webserver runs as, the webserver isn't going to be able to delete
files from there.

Jul 17 '05 #5

P: n/a
ph********@hotmail.com (phpfrizzle) writes:
Hi there again, thanks for taking the effort to read this.

It was a dir. I managed to get the upload script to work 'right'.
The file is uploaded, renamed & moved. And the file even gets CHmodded! :D
Executing script and it's folder are both set 'rwx rwx r-x'.

BUT... :-(
It only seems to work when i set the images dir-permissions to
'rwx rwx rwx' (0777) instead of 'rwx rwx r-x' (0755). So that's my first
question: is this dangereous, should it be different?
Yes and yes. But unless you are root, you can't change
owner/groupership of the upload images dir correctly and you'll have
to make do with world write perms.

And my second:
The file uploaded has uid & gid 'apache' instead of the uid/gid
i'm running the upload script from. I tried the following:
chown ( "../img/$id.jpg", "uid"); // correct uid
chgrp ( "../img/$id.jpg", "gid"); // correct gid
I think you are confused about who's who when these things are
running.

But that just gives me errors. :(
Warning: chown(): Operation not permitted
Warning: chgrp(): Operation not permitted
Of course. Non root users can't change file ownerships. This used to
be possible on some versions of Unix but generally isn't any more.

CHmod works though....
So how do i change them to the right settings?
You can't As a regular user. You need to get someone with root privs
on this box involved to change dir ownerships and modes as needed.

This is about all the help I can give you.

I am new to this uid/gid stuff, so please be gentle... ;)

Greetings

Jerry Sievers <je***@jerrysievers.com> wrote in message news:<m3************@prod01.jerrysievers.com>...

What is this a file or dir? If it's a dir and isn't owned by the UID
that webserver runs as, the webserver isn't going to be able to delete
files from there.


--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/
Jul 17 '05 #6

P: n/a
Well, thank you again Jerry for taking the effort.
I understand what you mean...

What i don't get, is that i am the 'owner' of the site, and i have
an admin panel etc. to create users etc. Is it in there, or could it be
useful to contact the host about this?

Thanks again Jerry!

Greetings phpfrizzle

Jerry Sievers <je***@jerrysievers.com> wrote in message news:<m3************@prod01.jerrysievers.com>...
ph********@hotmail.com (phpfrizzle) writes:
Hi there again, thanks for taking the effort to read this.

It was a dir. I managed to get the upload script to work 'right'.
The file is uploaded, renamed & moved. And the file even gets CHmodded! :D
Executing script and it's folder are both set 'rwx rwx r-x'.

BUT... :-(
It only seems to work when i set the images dir-permissions to
'rwx rwx rwx' (0777) instead of 'rwx rwx r-x' (0755). So that's my first
question: is this dangereous, should it be different?


Yes and yes. But unless you are root, you can't change
owner/groupership of the upload images dir correctly and you'll have
to make do with world write perms.

And my second:
The file uploaded has uid & gid 'apache' instead of the uid/gid
i'm running the upload script from. I tried the following:
chown ( "../img/$id.jpg", "uid"); // correct uid
chgrp ( "../img/$id.jpg", "gid"); // correct gid


I think you are confused about who's who when these things are
running.

But that just gives me errors. :(
Warning: chown(): Operation not permitted
Warning: chgrp(): Operation not permitted


Of course. Non root users can't change file ownerships. This used to
be possible on some versions of Unix but generally isn't any more.

CHmod works though....
So how do i change them to the right settings?


You can't As a regular user. You need to get someone with root privs
on this box involved to change dir ownerships and modes as needed.

This is about all the help I can give you.

I am new to this uid/gid stuff, so please be gentle... ;)

Greetings

Jerry Sievers <je***@jerrysievers.com> wrote in message news:<m3************@prod01.jerrysievers.com>...

What is this a file or dir? If it's a dir and isn't owned by the UID
that webserver runs as, the webserver isn't going to be able to delete
files from there.

Jul 17 '05 #7

P: n/a
ph********@hotmail.com (phpfrizzle) writes:
Well, thank you again Jerry for taking the effort.
I understand what you mean...

What i don't get, is that i am the 'owner' of the site, and i have
an admin panel etc. to create users etc. Is it in there, or could it be
useful to contact the host about this?
I think you should contact them. Those admin panels can only do so
much. The rest needs to be done as root, by manual login (telnet, ssh
etc.) most likely.

Thanks again Jerry!

Greetings phpfrizzle

Jerry Sievers <je***@jerrysievers.com> wrote in message news:<m3************@prod01.jerrysievers.com>...


--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/
Jul 17 '05 #8

P: n/a
Ok Jerry, thanks a lot, i'll contact them.
Thanks for helping with all this.

The original problem is still solved... :D

Greetings and thanks again!

Jerry Sievers <je***@jerrysievers.com> wrote in message news:<m3************@prod01.jerrysievers.com>...
ph********@hotmail.com (phpfrizzle) writes:
Well, thank you again Jerry for taking the effort.
I understand what you mean...

What i don't get, is that i am the 'owner' of the site, and i have
an admin panel etc. to create users etc. Is it in there, or could it be
useful to contact the host about this?


I think you should contact them. Those admin panels can only do so
much. The rest needs to be done as root, by manual login (telnet, ssh
etc.) most likely.

Thanks again Jerry!

Greetings phpfrizzle

Jerry Sievers <je***@jerrysievers.com> wrote in message news:<m3************@prod01.jerrysievers.com>...

Jul 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.