Very Simple .. Please Check This Code
Posted: Sat Jan 13, 2007 11:42 pm
This code should take a Post from the user and delete a file after doing some checking
the process
Post Delete Code By User > Check > Search the DB for the File Name Related To This Delete Code > Check > Delete From The DataBase And Server
can you please take a look at it and tell me if there is anything need to be fixed
the process
Post Delete Code By User > Check > Search the DB for the File Name Related To This Delete Code > Check > Delete From The DataBase And Server
can you please take a look at it and tell me if there is anything need to be fixed
Code: Select all
<?php
//-------------------------------------- check if the post ( the delete code ) is a number
if ( is_numeric($_POST[dnumber]) )
{
$dnumber = $_POST[dnumber];
} else {
die('');
}
//----------------------------------------------------------------
// --------------------- connect to the database where we will search for the file that is related to the delete code
$con = mysql_connect("localhost","*****","*****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("vbpron_Upload", $con);
$query="SELECT COUNT(*) FROM files Where dnumber = '$_POST[dnumber]'";
$result_of_count = mysql_query($query,$con);
$num_of_data = mysql_result($result_of_count,0,0);
if ($num_of_data == 0) {
echo $num_of_data;
exit();
}
else {
$result = mysql_query("SELECT * FROM files Where dnumber = '$_POST[dnumber]'");
$filename = mysql_result($result, 0);
//-------------------------------------- Check if the 1st 32 strings of the file that is related to the delete code are numbers ( all the files are named as a 32 numberd then the extension ( ex 48682042777251313657382990437535.jpg )
if ( is_numeric(substr($filename,0,32)) )
{
} else {
exit();
}
$sqll="DELETE FROM files WHERE dnumber = '$_POST[dnumber]'";
mysql_query($sqll,$con);
unlink("files/".$filename);
echo 'Done';
}
mysql_close($con);
?>