Current location: Hot Scripts Forums » Programming Languages » PHP » Problem Deleting files with PHP


Problem Deleting files with PHP

Reply
  #1 (permalink)  
Old 01-31-08, 10:45 PM
sccc2008 sccc2008 is offline
Newbie Coder
 
Join Date: Jan 2007
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Problem Deleting files with PHP

Hello Everyone,

I am having a problem deleting files with PHP. The script I am using to delete a file is as follows:

PHP Code:



$file 
"http://www.mysite.com/files/somefile.jpg";

unlink($file); 
I understand that this is file deletion in its simplest, however, this script will not delete the file. If anyone has a better idea of how to delete a file, I am all ears! Anyways, this is proly a PHP noob subject, but I had to ask the experts on this one.
Reply With Quote
  #2 (permalink)  
Old 01-31-08, 10:49 PM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
use chmod to make sure the settings are correct before unlinking
PHP Code:

chmod("/path/to/file"0777); 

Jay
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #3 (permalink)  
Old 01-31-08, 10:51 PM
sccc2008 sccc2008 is offline
Newbie Coder
 
Join Date: Jan 2007
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
yeah, ive got that in there as well. the current CHMOD on that directory is 755, and i can set it to 777. thats not a problem. Something that i was concerned about is that I am using a shared hosting account.

Is it possible that the hosting company has disabled PHP file deletion via this method?
Reply With Quote
  #4 (permalink)  
Old 01-31-08, 10:54 PM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Hmm, it's highly unlikely to be disabled
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #5 (permalink)  
Old 01-31-08, 11:02 PM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Ah, just noticed what the problem is lol
you are trying to delete a url. you have to delete the file by path name
such as
PHP Code:

unlink ("/home/username/public_html/files/somefile.jpg"); 

Jay
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #6 (permalink)  
Old 02-01-08, 04:51 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
and if that doesn't work, check your group permissions. Probably apache is running under a different group, and might not have the permission to delete files and folders as well as creating and changing them
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with deleting data from mysql using php maxat PHP 4 08-25-09 11:08 AM
deleting multiple records from MYSQL database using PHP sujata_ghosh PHP 5 06-04-09 03:07 AM
PHP Communication Problem Califer PHP 0 07-05-06 12:07 AM
php in linux problem usman PHP 6 05-15-04 11:57 AM
Upload Script Problem!!! seanknighton Perl 0 03-21-04 09:54 PM


All times are GMT -5. The time now is 07:34 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.