Deleting Images
Posted: Mon Nov 16, 2009 10:39 am
Hi all,
I've got a db with a table "pictures" which stores file paths to images that users have uploaded.
I'm trying to allow users to delete chosen images.
From a Flash front end (don't be put off it's the php I'm struggling with ! ) I give a variable of "toPHP"
which contains the complete file path i.e. /members/1/images/6.jpg my php script converts this to
it's own local variable of "$fromFlash" and I'm wondering what I've got wrong in the following code...
Best wishes
Monty
I've got a db with a table "pictures" which stores file paths to images that users have uploaded.
I'm trying to allow users to delete chosen images.
From a Flash front end (don't be put off it's the php I'm struggling with ! ) I give a variable of "toPHP"
which contains the complete file path i.e. /members/1/images/6.jpg my php script converts this to
it's own local variable of "$fromFlash" and I'm wondering what I've got wrong in the following code...
Code: Select all
<?php
session_start();
if(isset($_GET['id']) || isset($_POST['id']));
else if (isset($_SESSION['id'])) {
$id = $_SESSION['id'];
} else {
include_once "register.php";
exit();
}
include_once "scripts/connect_to_mysql.php";
$fromFlash = $_POST['toPHP'];
$delete_file = ($fromFlash);
$sql = mysql_query("DELETE FROM pictures WHERE dirpath = "$fromFlash";")
or die (mysql_error());
if(!unlink($fromFlash)) die("Failed to delete file");
else{
$toFlash = "&toFlash=";
$toFlash .= "Image has been deleted";
echo $toFlash;
}
?>
Monty