Hi all ,
I have googled for an answer for this question but most of them are so complicated. Can anyone suggest a simple article on this topic or show me step by step how to solve this.
I want to upload an image to a folder and show this image as a background for a <div>. I have managed to preview the image without uploading it to the folder (But it wont crop or re-size)
what I have done so far : -
"index.php"
<form id="imageform" enctype="multipart/form-data" method="post" action="upload.php">
<input id="fileToUpload" type="file" name="fileToUpload"/>
<input type="submit" value="Upload Image" />
</form>
// preview the image here (width:620px,height:516px)
<div id="image_preview"></div>
"index.js"
$("input[name='fileToUpload']").on("change", function(){
var files = !!this.files ? this.files : [];
if ( !files.length || !window.FileReader ) return;
if ( /^image/.test( files[0].type ) ) {
var reader = new FileReader();
reader.readAsDataURL( files[0] );
reader.onloadend = function(){
$("#image_preview").css("background-image", "url(" + this.result + ")"); }
}
});
"upload.php"
.......