Theboy22 Posted March 30, 2022 Report Posted March 30, 2022 am urmatorul script: <?php $path = "upload"; if(isset($_POST['file']) && is_array($_POST['file'])) { foreach($_POST['file'] as $file) { unlink($path . "/" . $file) or die("Failed to <strong class='highlight'>delete</strong> file"); } header("location: " . $_SERVER['REQUEST_URI']); //redirect after deleting files so the user can refresh without that resending post info message } ?> <form name="form1" method="post"> <?php $path = "upload"; $dir_handle = @opendir($path) or die("Unable to open folder"); while (false !== ($file = readdir($dir_handle))) { if($file == "index.php") continue; if($file == ".") continue; if($file == "..") continue; echo "<input type='CHECKBOX' name='file[]' value='$file'>"; echo "<a href='upload/$file' target='_blank'>"; echo "<img src='upload/$file' alt='$file' style='height: 100px; width: 100px;'/></a> "; } closedir($dir_handle); ?> <br> <input type="submit" name="Delete" value="Delete"> </form> scriptul imi afiseaza fotografiile din folderul UPLOAD, dar as vrea sa le afiseze in ordine cronologica cum au fost upldate . Mentionez fotograriile cand sunt uplodate in folderul UPLOAD au numele la data si ora de upload Exemplu: 2022-03-30-14-33-33_62444e1d7cf18.jpg. Imi cer scuze ca primul meu topic a inceput cu o cerere de ajutor. Va multumesc anticipat Quote
Wav3 Posted March 30, 2022 Report Posted March 30, 2022 (edited) Parcurgi lista de fisiere (acel while al tau), extragi data din fiecare nume (explode dupa _), o convertesti in timestamp (strtotime) si formezi un array cu fisierele. Ex.: $FILES_LIST[$file_timestamp] = $file; Apoi sortezi $FILES_LIST, apoi parcurgi array-ul si-l afisezi. In loc de $file, cand formezi array-ul de fisiere, poti sa-l faci un pic mai "complex", adica de forma: <?php $FILES_LIST[$file_timestamp] = array( "name"=>$file_name, // aici trebuie sa extragi numele din path banuiesc "path"=>$file, "size"=>$file_size, // aici iei filesize-ul dupa $file // etc ); ?> Edited March 30, 2022 by Wav3 1 Quote
Theboy22 Posted March 30, 2022 Author Report Posted March 30, 2022 multumesc mult, intrebarea mea este, cum implementez ce ai zi tu la mine in scriptul de mai sus? Quote
Amek Posted March 31, 2022 Report Posted March 31, 2022 Ai putea inlocui $dir_handle = @opendir($path) or die("Unable to open folder"); while (false !== ($file = readdir($dir_handle))) { if($file == "index.php") continue; if($file == ".") continue; if($file == "..") continue; echo "<input type='CHECKBOX' name='file[]' value='$file'>"; echo "<a href='upload/$file' target='_blank'>"; echo "<img src='upload/$file' alt='$file' style='height: 100px; width: 100px;'/></a> "; } closedir($dir_handle); Cu function sortByTime($a, $b) { $datePuzzleA = explode("-", explode("_", $a)[0]); $dateA = strtotime(implode("-", array_slice($datePuzzleA, 0, 3))." ".implode(":", array_slice($datePuzzleA, 3, 3))); $datePuzzleB = explode("-", explode("_", $b)[0]); $dateB = strtotime(implode("-", array_slice($datePuzzleB, 0, 3))." ".implode(":", array_slice($datePuzzleB, 3, 3))); if ($a === $b) { return 0; } return $b > $a ? -1 : 1; } $files = array_diff(scandir($path), array('.', '..', 'index.php')); usort($files, "sortByTime"); foreach($files as $file) { echo "<input type='CHECKBOX' name='file[]' value='$file'>"; echo "<a href='upload/$file' target='_blank'>"; echo "<img src='upload/$file' alt='$file' style='height: 100px; width: 100px;'/></a> "; } Desi nu cred ca e cea mai eleganta solutie. Quote