<script type="text/javascript">
$(document).ready(function(){
$("#fsubmit").click(function(){
var img = $('input[type="file"]').val(); //.files[0] i have tried this code too
var imgdetail = $("#detail").val();
var verify = "fsubmit";
//formdata = new FormData();
//formdata.append('images', document.getElementById("images").val());
//formdata.append('detail', imgdetail);
//formdata.append('fsubmit', verify);
if(img == ""){
$("#message").html("<span style='color:red;'>The image field should not be left empty.</span>");
}
else
{
$.ajax({
type: "POST",
url: "image_upload.php",
data:"images="+img+"&detail="+imgdetail+"&fsubmit="+fsubmit,
//contentType: false,
//processData: false,
success: function(data){
//alert(data);
$("#message").html(data);
}
});
}
return false;
});
});
</script>
<form method="post" id="imgform" name="imgform" action="" enctype="multipart/form-data">
<input class="btn btn-secondary" type="file" name="images" id="images" onchange="loadFile(event)">
<textarea class="input-texts" id="detail" name="detail" placeholder="Details"></textarea>
<div class="detailss">
<button class="btn btn-secondary" type="submit" name="fsubmit" id="fsubmit">Upload</button>
</form><?php
include_once('cpfdb-config.php');
if(isset($co, $_POST['fsubmit'])){
$target_dir = "http://www.codingforums.com/images/uploads/";
$image = $_FILES['images']['name'];
$details = mysqli_real_escape_string($co,$_POST['detail']);
$dateadded = date("Y-m-d H:i:s");
$validextensions = array("jpeg", "JPG", "png", "gif", "jpg", "JPEG", "PNG", "GIF"); // Extensions which are allowed.
$ext = explode('.', basename($_FILES['images']['name'])); // Explode file name from dot(.)
$file_extension = end($ext);
$target_path2 = $target_dir.md5(uniqid()). "." .$ext[count($ext) -1];// Set the target path with a new name of image.
$image = $target_path2;
// Increment the number of uploaded images according to the files in array.
if (($_FILES["images"]["size"] < 1000000) // Approx. 100kb files can be uploaded.
&& in_array($file_extension, $validextensions)) {
if (move_uploaded_file($_FILES['images']['tmp_name'], $target_path2)) {\some code here}
?>
برچسب:
نویسنده: آیلین رضوانی