I have a simple admin page which is used to edit the content on a main page.
On the admin page, you can upload a file. (which works)
here's the php upload code:
$target_dir = "../images/";
$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.";
}
}
However...
When I upload the file, I want to automatically append it to an element on the main page (a gallery of images).
The CSS makes thumbnail views as shown on w3schools (http://www.w3schools.com/css/css_image_gallery.asp) and when you click the image it opens a new window with the full image.
Here is my HTML code:
<aside id="rooms">
<h3>Room Types</h3>
<div class="img">
<p>1 Bedroom</p>
<a target="_blank" href="./images/room1bed.jpg"><img src="./images/room1bed.jpg" width="110" height="90"></a>
</div>
<div class="img">
<p>2 Bedroom</p>
<a target="_blank" href="./images/room2bed.jpg"><img src="./images/room2bed.jpg" width="110" height="90"></a>
</div>
<div class="img">
<p>Suite</p>
<a target="_blank" href="./images/roomsuite.jpg"><img src="./images/roomsuite.jpg" width="110" height="90"></a>
</div>
</aside>
Basically, I want to use the JQuery append to add the newly uploaded file to the aside that contains the divs for the images...
How do i grab the filename on upload and implement the append?
Here is what I basically want to do...
$( "#rooms" ).append( "<div class="img">
<p>**new description**</p>
<a target="_blank" href="./images/**uploaded file**"><img src="./images/**uploaded file**" width="110" height="90"></a>
</div>" );