PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Oct 17, 2017 8:28 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Thu Mar 16, 2017 5:08 pm 
Offline
Forum Contributor
User avatar

Joined: Mon Jul 26, 2010 1:30 pm
Posts: 174
Location: Florida
Hi Celauran,

Spent a few hours trying to research this to no avail. Thought I would run it by you to see if you catch the problem.

Trying to delete an empty folder that is:

1. Known to be completely empty
2. Permission'd with 0777

Syntax: [ Download ] [ Hide ]
if(isset($_GET['delete_photo'])) {

                $document_folder = $_SESSION['student_first_name'] . "-" . $_SESSION['student_last_name'];
                $target_dir = "../_photos/".$document_folder."/";

                        $folder_check = $target_dir;

                        if (file_exists($folder_check)) {

                                array_map('unlink', glob("$target_dir/*.*")); //THIS WORKS FINE

                                        $handle = opendir($target_dir); // DIDN'T MAKE ANY DIFFERENCE
                                        closedir($handle); // DIDN'T MAKE ANY DIFFERENCE

                                                rmdir("../_photos/Tom-Jones"); // NO-GO ON LOCALHOST OR SERVER
                        }

        }
 


The file in the folder does delete properly on both localhost and server, but folder doesn't delete on localhost or server.

I tried manually creating a folder on the server and gave it 0777 permissions. After trying to delete it with the script above, I noticed the permisssions were changed to 0777.

I hard-coded the folder "Tom-Jones" just as a test. I also used getcwd() to ensure I was calling script from proper location.

Localhost is using UniServer (localhost) on Windows 10, but I don't think it's a path issue anymore.

Thanks for any help you can provide.

Michael


Top
 Profile  
 
PostPosted: Fri Mar 17, 2017 7:05 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6384
Location: Montreal, Canada
Are you seeing any errors? mkdir/rmdir works as expected for me. Might be different on account of being on Windows? Have you tried using DIRECTORY_SEPARATOR instead of '/'?

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Fri Mar 17, 2017 7:16 am 
Offline
Forum Contributor
User avatar

Joined: Mon Jul 26, 2010 1:30 pm
Posts: 174
Location: Florida
I thought it might be a windows thing too, which is why I then uploaded to the server. But, it didn't work there either.


Top
 Profile  
 
PostPosted: Fri Mar 17, 2017 7:33 am 
Offline
Forum Contributor
User avatar

Joined: Mon Jul 26, 2010 1:30 pm
Posts: 174
Location: Florida
.... and no errors.


Top
 Profile  
 
PostPosted: Fri Mar 17, 2017 7:40 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6384
Location: Montreal, Canada
Checked for hidden files, too? Checked that the directory can be deleted (is_writeable)?

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Fri Mar 17, 2017 7:44 am 
Offline
Forum Contributor
User avatar

Joined: Mon Jul 26, 2010 1:30 pm
Posts: 174
Location: Florida
I did check for hidden files. cPanel tells me no files ("directory empty"). I checked to make sure the setting to allow me to see hidden files was turned on and it was.

Folder showed permissions of 0777, so that's all permissions, right?


Top
 Profile  
 
PostPosted: Fri Mar 17, 2017 7:50 am 
Offline
Forum Contributor
User avatar

Joined: Mon Jul 26, 2010 1:30 pm
Posts: 174
Location: Florida
are you saying rmdir, in general, works on your system ... or ... you used my code to test it and my code worked on your system?

By the way, I also checked my phpini setting to ensure rmdir wasn't being prevented as a precautionary measure.


Top
 Profile  
 
PostPosted: Fri Mar 17, 2017 7:59 am 
Offline
Forum Contributor
User avatar

Joined: Mon Jul 26, 2010 1:30 pm
Posts: 174
Location: Florida
Ha! Disregard...

Not sure why, but now it seems to be working local server.

I've been making a few additions, which required some minor changes.

Seems it must have been a programming error that is now correct.

Thank you for your help.


Top
 Profile  
 
PostPosted: Fri Mar 17, 2017 8:05 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6384
Location: Montreal, Canada
Tried your exact code locally just now and it's working fine. Is _photos/ writeable?

EDIT: Ha! Too late! Glad you got it working.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Exabot [Bot] and 22 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group