Итак, у меня есть массив из файла, который выглядит следующим образом
0:uploads/Zdjęcie0232.jpg
0:uploads/Zdjęcie0222.jpg
0:uploads/duparomana.jpg
0:uploads/dddfsdfsd.jpg
0:uploads/6.jpg
это сделано при загрузке, которая выглядит так
<?php
$licznik = 0;
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
}
/* Check file size
}*/
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file//
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
// open file to read
$fp = fopen("database.dat", "r");
$separator=':';
//read data
$stareDane = fread($fp, filesize("database.dat"));
// close file
fclose($fp);
// create new data
$noweDane = $licznik . $separator . $target_file;
$noweDane .= PHP_EOL . $stareDane;
// open file to write
$fp = fopen("database.dat", "w");
// save data
fputs($fp, $noweDane);
// close file
fclose($fp);
} else {
echo "Sorry, there was an error uploading your file.";
}
}
echo "Zaraz nastąpi przekierowanie";
sleep (3);
header("Location: /index.php?filename=$target_file", true, 301);
exit();
?>
Так в разделе
// Check if file already exists
if (file_exists($target_file)) {
}
Я хочу найти, если в файле database.dat есть строка с путем к файлу. Далее я хочу увеличить число до :
на единицу, а затем оставить без сохранения этого файла (изображения) второй раз в папке. Я попробовал немного с сообщениями, которые уже были сделаны здесь, но я действительно застрял здесь.
Пример массива, с которым я застрял:
array (size=24) 0 =>
array (size=2)
0 => string '0' (length=1)
1 => string 'uploads/Zdjęcie0232.jpg ' (length=25) 1 =>
array (size=2)
0 => string '0' (length=1)
1 => string 'uploads/Zdjęcie0228.jpg ' (length=25) 2 =>
array (size=2)
0 => string '0' (length=1)
1 => string 'uploads/Zdjęcie0262.jpg ' (length=25)