Closed Thread Icon

Topic awaiting preservation: Trouble in removing files from server Pages that link to <a href="https://ozoneasylum.com/backlink?for=27568" title="Pages that link to Topic awaiting preservation: Trouble in removing files from server" rel="nofollow" >Topic awaiting preservation: Trouble in removing files from server\

 
Author Thread
dade
Nervous Wreck (II) Inmate

From: Kansas, just this side of the rainbow
Insane since: Sep 2004

posted posted 02-28-2006 20:59

I am creating an admin section on an intranet site. I need to remove files from a list that is on a database, so I am using the unlink() function. It works fine when I manually type the filename (i.e. remax.jpg) into the pathname. However, when I try and insert the variable from the database, it is completely ignored. The variable is working because it deletes the entry from the database. I have tried moving the function around thinking that it was a problem with my ordering of events, but no luck. Any suggestions would be appreciated. Code follows:

code:
$order_logo = "SELECT * FROM logo_table WHERE id = '$_POST[del_logo]' ";
		$get_logo = mysql_query($order_logo, $login) or die(mysql_error());
		
		while ($row = mysql_fetch_row($get_logo)) {
			$id = $row['id'];
			$filename = $row['logo'];
			$name = $row['logo_name'];
		
			echo "$filename";
		}		
		
		//This will delete the file from the server.
		chmod( "logos/$filename, 777");
		unlink( "logos/$filename");
		
		//This will reset the rows that contain that logo in realestate_info_table to 'NONE'.
		$reset_logo = "UPDATE realestate_info_table SET logo = 'NONE' WHERE logo = '$filename' ";
		mysql_query($reset_logo) or die(mysql_error());
		
		//This will delete the entry from logo_table.
		$delete_entry = "DELETE FROM logo_table WHERE id = '$_POST[del_logo]' ";
		mysql_query($delete_entry) or die(mysql_error());



This patient is ready for his medication!

dade
Nervous Wreck (II) Inmate

From: Kansas, just this side of the rainbow
Insane since: Sep 2004

posted posted 02-28-2006 21:28

Okay, forgive my idiocy, I found my error.

code:
while ($row = mysql_fetch_row($get_logo)) {
                        $id = $row['id'];
                        $filename = $row['logo'];
                        $name = $row['logo_name'];



Should be...

code:
while ($row = mysql_fetch_row($get_logo)) {
                        $id = $row['0'];
                        $filename = $row['1'];
                        $name = $row['2'];



I spent about a week off and on trying to get this blasted thing working, why I never saw that... Sorry for the time reading this.

This patient is ready for his medication!

« BackwardsOnwards »

Show Forum Drop Down Menu