#!/usr/bin/env php query($sql)) { if ($result->num_rows > 0) { $continue = true; } else { $continue = false; } //$results = $result->fetch_all(MYSQLI_ASSOC); //for PHP with mysql driver (not mysqlnd) - without fetch_all function for ($results = array(); $tmp = $result->fetch_array(MYSQLI_ASSOC);) $results[] = $tmp; $result->close(); // foreach ($results as $image) { // echo "\n".print_r($image, true); // get category path $filename = $image['file']; $full_q_path = explode('///', $image['full_path']); $real_path = ''; $real_path_a = array(); $storage_category_id = 0; foreach ($full_q_path as $el) { list($id, $fs_dir, $virt_dir) = explode(':::', $el); if (empty($fs_dir)) { $fs_dir = preg_replace("/[^\\w-_\ ]+/",'',$virt_dir); $fs_dir = trim($fs_dir); $dbc->query("UPDATE `{$prefixeTable}categories` pc SET pc.dir='".$dbc->real_escape_string($fs_dir)."', site_id = {$site_id} WHERE pc.id = {$id} "); } $real_path_a[] = $fs_dir; $storage_category_id = $id; } $real_path = './galleries/'. implode('/',$real_path_a); echo "\n".$real_path.'/'. $image['file']; if(is_dir($real_path)) { echo ' '; } else { mkdir($real_path, 0775, true); echo '+'; } // move $new_file_path = $real_path.'/'.$image['file']; copy($image['path'], $new_file_path); //rename($image['path'], $new_file_path); echo ' [v]'; //update path, storage category $dbc->query("UPDATE `{$prefixeTable}images` SET `path`='".$dbc->real_escape_string($new_file_path)."' WHERE id = {$image['id']}"); if ($storage_category_id > 0) { $dbc->query("UPDATE `{$prefixeTable}images` SET storage_category_id = $storage_category_id WHERE id = {$image['id']}"); } } } else { $continue = false; } } while ($continue); $dbc->close(); ?>