Jump to content

Deleting files from list in array, sort of


btw_nc

Recommended Posts

I have certain photos that need to be deleted from the server. The photos all use the same naming convention: 346986_1.jpg, 346986_2.jpg, etc.  The part before the underscore is the ID number in the mySQL dB. There can be anywhere from one to fifteen photos associated with an entry.

 

I have a query set up to find the photos that need deleting. The query just returns the ID field, not the entire filename. I can display the list of ID's using this:

 

while($row = mysqli_fetch_array($resultb)){
echo $row['MLNumber'];
echo "<br />";}

 

I have the path to the images set

 

$imgpath = $_SERVER['DOCUMENT_ROOT']."/search/photos/";

 

How can I append a wildcard (for the underscore and incremental photo number) and the file suffix to the ID numbers, then delete the resulting filenames?

 

Can someone tell me if this is on the right track? $imgpath is not being appended as far as I can see.

 

$resultquery = "SELECT IDNumber FROM Table WHERE IndexPhoto='2'";

$resultb = mysqli_query($cxn,$resultquery)
or die ("Could not peform query b.");

// while ($row = mysqli_fetch_array($resultb)){
// echo $row[MLNumber] . "<br />";
// }
$imgpath = $_SERVER['DOCUMENT_ROOT']."/search/photos";

foreach ($resultb as &$value) {
$value = $value . $imgpath;
}
while ($row = mysqli_fetch_array($resultb)){
echo $row[iDNumber] . "<br />";
}

unset ($value);	

mysqli_close($cxn);

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.