我刚刚设置了一个fileupload.php,这样我就可以上传文件了,但我很高兴能够立即在我想要的页面上设置文件并使用我指定的css。有没有办法做到这一点?我希望有三列照片,观看者可以在我上传文件时看到这些照片,所以我不必每次想要将照片添加到页面时手动将其添加到代码中。
我已经知道如何使用照片制作网格,但我真的很感兴趣如何将所有照片上传到页面,以便立即放置在该网格上。
我的 graphics.php 页面:
<?php include 'includes/header.php' ?>
<div class="graphics_content">
<div class="page_top_image">
<img src="includes/img/heartfx_graphics.png" class="img-responsive" alt="Responsive image">
</div>
</div>
<div class="photo_upload">
<div class="photo_upload_form">
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<br>
<input type="file" name="fileToUpload" id="fileToUpload">
<br>
<input type="submit" value="Upload Image" name="submit">
</form>
</div>
</div>
我的 upload.php 页面:
<?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 an actual image or a 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 != "png") {
echo "Sorry, only PNG 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.";
}
}
?>
提前感谢您的帮助。如果我希望我提供的代码中有任何内容,我可以这样做。
祝你好运, CODI