1
Hier ist mein Code und meine Frage ist, wie benenne ich die Datei beim Hochladen darunter auch das Hochladen der Dateigröße. also kann ich die Dateigröße auch in meinem Bericht abrufen.Datei beim Hochladen und Löschen ausgewählter Dateien aus mehreren Ordnern umbenennen
<?php
if ((!isset($_GET['admin'])) and (!isset($_GET['admin']))) {
$valid_formats = array(
"jpg",
"png",
"gif",
"zip",
"bmp"
);
$max_file_size = 100000000000 * 100000000000; //100 kb
$path = "../week/"; // Upload directory
$count = 0;
if (isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
// Loop $_FILES to execute all files
foreach ($_FILES['files']['name'] as $f => $name) {
if ($_FILES['files']['error'][$f] == 4) {
continue; // Skip file if any error found
}
if ($_FILES['files']['error'][$f] == 0) {
if ($_FILES['files']['size'][$f] > $max_file_size) {
$message[] = "$name is too large!.";
continue; // Skip large files
} elseif (!in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats)) {
$message[] = "$name is not a valid format";
continue; // Skip invalid file formats
} else { // No error found! Move uploaded files
if (move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path . $name)) {
$count++; // Number of successfully uploaded files
$sql = "INSERT INTO pics_uploads(gf,path) VALUES('$name','$path')";
mysql_query($sql);
}
}
}
}
}
?>
<div class="wrap">
\t \t <h1>Events Name</h1>
\t \t <?php
# error messages
if (isset($message)) {
foreach ($message as $msg) {
printf("<p class='status'>%s</p></ br>\n", $msg);
}
}
# success message
if ($count != 0) {
printf("<p class='status'>%d files added successfully!</p>\n", $count);
}
?>
\t \t <p>Max file size 10MB, Valid formats jpg, png, gif</p>
\t \t <br />
\t \t <br />
\t \t <!-- Multiple file upload html form-->
\t \t <form action="" method="post" enctype="multipart/form-data">
\t \t \t <input type="file" name="files[]" multiple accept="image/*">
\t \t \t <input type="submit" value="Upload">
\t \t </form>
<br />
<center><table width="80%" border="1" bordercolor="#FF0033" >
<tr>
<th>MultiDelete</th>
<td>File Name</td>
<td>File Location</td>
<td>Upload Date</td>
<td>View (Click to View)</td>
<th colspan="2">ACTION</th>
</tr>
<?php
$sql = "SELECT * FROM `pics_uploads` WHERE `gf`";
$result_set = mysql_query($sql);
while ($row = mysql_fetch_array($result_set)) {
?>
<tr>
<td ><font color="#000"><input name="checkbox[]" type="checkbox" value="<?
echo $row['id'];
?>"></font></td>
<td><?php
echo $row['gf'];
?></td>
<td><?php
echo $row['path'];
?></td>
<td><?php
echo $row['curtime'];
?></td>
<td><a href="../week1/<?php
echo $row['gf'];
?>" target="_blank"><?php
echo '<img src="../week1/' . $row['gf'] . '" width="40px" height="20px" border="2" />';
?></a></td>
<td><a href="javascript:remove(<?php
echo $row['id'];
?>)">Delete file</a></td>
</tr>
<?php
}
?> <tr>
<td>
\t <input name="delete" type="submit" id="delete" value="Delete"></td>
\t \t </tr>
</table></center>
<?php
}
?>
Dies ist zum Löschen. Ich möchte sagen, dass die Ordnernamen woche1, woche2 woche3, wochen lauten, aber lösche nur ausgewählte Dateien daraus.
<?php
include_once 'dbconfig.php';
if (isset($_GET['remove_id'])) {
$res = mysql_query("SELECT file FROM pics_uploads WHERE id=" . $_GET['remove_id']);
$row = mysql_fetch_array($res);
mysql_query("DELETE FROM pics_uploads WHERE id=" . $_GET['remove_id']);
unlink("week1/", week2, week3, week4 . $row['file']); //this didn't work
header("Location: index-1.php");
}
?>
Thanks @ aslem-patel Das funktionierte pefectly ok. Benötigen Sie immer noch Hilfe beim Löschen ausgewählter Dateien aus mehreren Ordnern. wie in meinem zweiten Code oben angegeben. –