vendredi 2 septembre 2022

i want to move the images to another directory if the status of the image is 1(active) i am able to move one record but not all

I want a simple guide on how can i transfer the images with active status to another directory here is my code:

Route::get('/', function () {
$path = public_path('images\products');
$allfiles = scandir($path);
$allfiles = array_diff(scandir($path), array('.', '..'));
$files = array();

foreach ($allfiles as $filename) {
    $file= File::get(public_path('images/products/'.$filename));}
    $files[] = [
        "file_name"=>$filename];
        // return $files;
            // return $files;

foreach($files as $file){
    $users = DB::table('tw_products')
    ->where('status', '=', 1)

    ->get('image') ;
if($users = $file['file_name']){
File::copy('images/products/'.$file['file_name'],'images/ActiveProducts/'.$file['file_name']);
    echo "File Moved";
  }
 }
  });

I want to compare the DB items(image and status) if the status of the image = 1 that image will be moved to another directory... I am doing some mistakes i am able to move 1 last product but others are not moving



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire