안녕하세요, 저는 PHP에서 아주 간단한 것을 달성하려고합니다. 새 이미지를 보내어 변경할 수있는 이미지를 표시하는 페이지를 가져오고 싶습니다.이 페이지는 내 PHP와 동일한 폴더에 저장되어 있습니다. 따라서 내 페이지를 열면 마지막으로 업로드 한 이미지를 갖게됩니다. Idealy 나는 croppie (https://foliotek.github.io/Croppie/)와 같은 방법으로 작물을 재배 할 수있을 것입니다. 그러나 단계를 이해하고 간단하게 유지하면 곡물은 나중에 저장됩니다..php 내 디렉토리에서 변경할 수있는 이미지를 표시하는 방법
나는 나 이미지를 업로드 할 수 있도록 지금까지 한 코드는
upload.php로 :
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
그래서뿐만 아니라 내가 갖고 싶어
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = 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)) {
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.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
및 index.html을 이미지의 미리보기가 표시되지만 특정 ID가있는 이미지 하나만 재고하려고합니다 (이유를 알고 싶다면 indesign으로 곧바로 이동하기 때문에 ...)
도움 주셔서 감사합니다. !!!
이 코드를 시도하면 "잘못된"에코가 나타납니다 ... – Odjone