meltingpoint Posted November 1, 2011 Share Posted November 1, 2011 I have a config file that lists a file like so.. $file1 = 'storagefolder/mydatabase.txt'; How can I delete the file "mydatabase.txt" that is in another directory 'storagefolder' ? unlink($file1); gives an error that says not such file or directory Quote Link to comment https://forums.phpfreaks.com/topic/250245-unlink-problems/ Share on other sites More sharing options...
xyph Posted November 1, 2011 Share Posted November 1, 2011 Perhaps you should echo $file1 and verify it's contents. Verify that the path is relative to your script, and if it isn't, use absolute paths. Quote Link to comment https://forums.phpfreaks.com/topic/250245-unlink-problems/#findComment-1284031 Share on other sites More sharing options...
meltingpoint Posted November 1, 2011 Author Share Posted November 1, 2011 echo does indeed echo out as above = storagefolder/mydatabase.txt because this script may wind up in any directory or subdirectory - I was trying to use relative link. Using absolute may prove problematic. Quote Link to comment https://forums.phpfreaks.com/topic/250245-unlink-problems/#findComment-1284050 Share on other sites More sharing options...
meltingpoint Posted November 1, 2011 Author Share Posted November 1, 2011 Below is my exact code. I can get the unlink() to work in other scripts- but not this one. Anyone see anything that would make unlink() not work? $file1, $file2 etc...are defined in the config file as exampled above. // switch($database) { case "maindb": $filetorestore = 'databases/BACKUPmaindatadb.txt' and $restored = $file2; break; case "homedb": $filetorestore = 'databases/BACKUPdchomedb.txt' and $restored = $file3; break; case "petsdb": $filetorestore = 'databases/BACKUPlostanimals.txt' and $restored = $file8; break; case "vehiclesdb": $filetorestore = 'databases/BACKUPvehicleslist.txt' and $restored = $file11; break; case "bikesdb": $filetorestore = 'databases/BACKUPbikelist.txt' and $restored = $file7; break; case "licensesdb": $filetorestore = 'databases/BACKUPbikelicenses.txt' and $restored = $file12; break; case "parkingdb": $filetorestore = 'databases/BACKUPparkingpermission.txt' and $restored = $file9; break; case "dispatchnotesdb": $filetorestore = 'databases/BACKUPdispatchnotes.txt' and $restored = $file6; break; case "usersdb": $filetorestore = 'databases/BACKUPuserpermissions.txt' and $restored = $file10; break; case "categoriesdb": $filetorestore = 'databases/BACKUPcategories.txt' and $restored = $file5; break; case "spcattndb": $filetorestore = 'databases/BACKUPspcattndatabase.txt' and $restored = $file13; break; default: $filetorestore = $file100; break; } // if(empty($filetorestore)){ $message = "<center>ERROR!- no database was selected/detected to be Backed-UP. Please try again. If problem persists- notify the Web/IT Administrator.</center>"; include("dcloginmessagepage.php"); exit; } // sleep(1);//---------------supposed fix for IIS Servers that copy() does not work well with------------ // if(!copy($filetorestore, $restored)) { $message = "<center>The RESTORATION of the Database was UNSUCCESSFUL!- Please notify the Administrator.</center>"; include("dcloginmessagepage.php"); exit; } else { $message = "<center>RESTORATION of the Database was sucessfull.</center>"; include("dcloginmessagepage.php"); exit; } // unlink($filetostore); // // //----------------------------------------------------------------------------------------------------------------------------- Quote Link to comment https://forums.phpfreaks.com/topic/250245-unlink-problems/#findComment-1284064 Share on other sites More sharing options...
meltingpoint Posted November 1, 2011 Author Share Posted November 1, 2011 hahahaha----------what a goof moment. My unlink() was outside the script for if it was successful it went to the message page and therefore was never being called. How funny. Well-------------that's how it goes sometimes. Cheers all.........lol.........lol Quote Link to comment https://forums.phpfreaks.com/topic/250245-unlink-problems/#findComment-1284067 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.