<html>
<head>
<title>Title</title>
</head>
<body>
<section class="container">
<div class="wrap">
<div class="gallery">
<div class="gallery-header">Galerija</div>
<div class="gallery-body">
<ul class="gallery-list">
<?php require 'admin/citati.php' ?>
</ul>
</div>
</div>
</div>
</section>
<section class="container2">
<div class="wrap2">
<div class="form">
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="text" name="ime-pjevaca" class="input" placeholder="Ime pjevaca"/>
<input type="text" name="ime-pjesme" class="input" placeholder="Ime pjesme"/><br />
<input type="file" name="fileToUpload" id="fileToUpload" /><br />
<input type="submit" value="Upload Image" name="submit">
</form>
</div>
</div>
</section>
<?php
$target_dir = "../images/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
$imePjevaca = $_POST['ime-pjevaca'];
$imePjesme = $_POST['ime-pjesme'];
$imeSlike = $_FILES['fileToUpload']['name'];
// 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)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// 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.";
$file = fopen("citati.php", "r+") or die("Unable to open file!");
$citat = "
<li class='gallery-li'>
<img src='images/$imeSlike' />
<div class='info'><span class='text'>$imePjevaca<br /> $imePjesme</span></div>
</li>";
fwrite($file, $citat);
fclose($file);
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
</body>
</html>
У меня есть скрипт PHP, когда пользователь загружает изображение, имя певца и имя исполнителя, он должен поместить его в тег li и записать в файл citati. php. Все хорошо в этом процессе, но когда PHP пишет строки кода, также по некоторым причинам удаляет 5-6 строчных кодов вверху файла. Я не могу найти решение исправить это. Я надеюсь, что кто-то узнает решение.