I need to delete image records (file paths) from a db and then delete the actual image
from a users directory. The way I have set this up (don't ask) means that to delete from the db
I need a path starting with a slash like this:
"/members/1/images/999.jpg"
and to delete the image from the dir I need a path WITHOUT a starting slash like this:
"members/1/images/999.jpg"
The file path is being delivered to the script from a Flash front end as a variable "toPHP" and it arrives WITH a
starting slash. (don't let the Flash bit put you off - it just uses POST to send data and it works fine).
SIMPLE QUESTION:
Having run some code using the string in "toPHP" to delete from the db how can I declare another local variable of
the same string WITHOUT the starting slash to use to delete the actual image ?
My current script attached (which works fine for the db delete WITH the slash and fine for the dir delete WITHOUT it)
Best wishes
Monty
Code: Select all
// DELETE the record from the db
include_once "scripts/connect_to_mysql.php";
$fromFlash = $_POST['toPHP'];
$returned_message = ($fromFlash);
$sql = mysql_query("DELETE FROM pictures WHERE dirpath = '$fromFlash';")
or die (mysql_error());
// Now delete the actual image from the members image folder
if(!unlink($returned_message)) die("Failed to delete file");
else{
$toFlash = "&toFlash=";
$toFlash .= $returned_message;
echo $toFlash;
}