file delete code not working - i'm using PhpNuke

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wqr786
Forum Newbie
Posts: 13
Joined: Fri Sep 08, 2006 2:47 am

file delete code not working - i'm using PhpNuke

Post by wqr786 »

im working on PhpNuke

i made a folder uploads/audio/
and within that folder i uploaded some files of .mp3 etc
now i need to delete those files using the php code

im trying to delete them with the following code but its not working:
unlink("uploads/audio/somefile.mp3");

but file is not being deleted. urgent help needed, please.

-Waqar
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I think you're going to need to get a bit more specific. Your code and errors from your error logs could be of use here for instance.
wqr786
Forum Newbie
Posts: 13
Joined: Fri Sep 08, 2006 2:47 am

Post by wqr786 »

well, the i made a .txt file, in the root the unlink() is working, but when i try to unlink() the file in a folder, it doesn't work, ill provide more information after a little debugging...

works
unlink("somefile.txt");

does not work:
unlink("folder1/folder2/somefile.txt");
User avatar
wtf
Forum Contributor
Posts: 331
Joined: Thu Nov 03, 2005 5:27 pm

Post by wtf »

check folder/file permissions
wqr786
Forum Newbie
Posts: 13
Joined: Fri Sep 08, 2006 2:47 am

here's my code, please help, file not being deleted...

Post by wqr786 »

patrikG | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


here's my code, help required, i can't figure out why the file is not being deleted.
besides this, im using EasyPHP on Windows XP, so if anyone knows how to check the files/folders permissions in it please let me know. however, please remember, the file.txt is deleted if its not in a folder, but if it is in a folder, im unable to to delete it.

Code: Select all

case "deleteaudio":
	if($_REQUEST['id']!=NULL)
	{
		//QUERY TO SELECT AND DELETE THE FILE FROM THE SERVER (LOCATION)
		$sql = "SELECT location FROM ".$prefix."_audio WHERE id=".$_REQUEST['id'];
		$result = $db->sql_query($sql);
               
                // row[location] variable is actualy the path and filename which is stored in database, so you can assume it
                // to be folder1/folder2/file.txt
		echo $row[location];
		//DELETING (UNLINKING) THE FILE
		if(unlink($row[location]))
		{
			echo "<p>File deleted from server, please wait ...</p>";
		}
		else
		{
			echo "<p>File NOT deleted from server location ...</p>";		
		}
		//QUERY TO DELETE THE DETAILS OF THE AUDIO FILE FROM DATABASE
		$sql="DELETE FROM ".$prefix."_audio WHERE id=".$_REQUEST['id'];
		$db->sql_query($sql);
		echo "<p>Audio successfully deleted from database ...</p>";
	}
	break;
patrikG | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Post by Mordred »

what do file_exists() and is_writable() say?
Post Reply