I have a system that allows user to upload PDF files and save the name of the file on the database.
How can I make this script works so user can delete all files from server whose name is not in my database?
This is what I actually have, but the script deletes all files. I don't know how to proceed.
<?php
include 'fimg.class.php';
require('../../../php/cone.php');
//header('Location: ../produccion.php');
$directory = "upload/";
//get all image files with a .jpg extension.
$images = glob($directory . "*");
foreach($images as $image)
{
$name = explode('_',$image);
$name = 'photos/' . $name[0];
$sql = mysql_query("SELECT imagen FROM r_alumnos");
if(mysql_num_rows($sql) == 0)
unlink($image);
}
?>