pano po ito maisave sa database sa folder lang kasi naisasave po..
ito code ko:
<div class="mt-3">
<label for="formFile" class="form-label ">Upload Image</label>
<input class="form-control" type="file" name="profile-pic" onchange ="displayPreview(this.files)" id="formFile">
</div>
<center>
<span id="preview"></span>
</center>
<hr class="my-4">
<button class="w-100 mb-2 btn btn-sm btn-lg rounded-3 btn-primary" name= "update" type="submit">Update</button>
</div>
</div>
</form>
<?php
$target_dir = "../photo_folder/";
$uploadErr = "";
if (isset($_POST["update"])){
$target_file = $target_dir . "/" . basename($_FILES["profile-pic"]["name"]);
$uploadOk = 1;
if(file_exists($target_dir)) {
$target_file = $target_dir . rand(1,9) . rand(1,9) . rand(1,9) . rand(1,9) . "_" .basename($_FILES["profile-pic"]["name"]);
$uploadOk = 1;
}
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if($_FILES["profile-pic"]["size"] > 5000000000000000000 ) {
$uploadErr = "Sorry, your file is too large";
$uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
$uploadErr = "Sorry, only JPG, PNG, JPEG and GIF files are allowed";
$uploadOk = 0;
}
if($uploadOk == 1) {
if (move_uploaded_file($_FILES["profile-pic"]["tmp_name"], $target_file)){
echo "the file has been uploaded";
}else {
echo "sorry , there was an error uploading file.";
}
}
}
?>
<span class="error"><?php echo $uploadErr; ?></span>
<script type = "application/javascript">
var _URL = window.URL || window.webkitURL;
function displayPreview(files){
var file = files[0];
var img = new Image();
var sizeKB = file.size / 1024;
img.onload =function(){
$(img).addClass('resized-image');
$('#preview').append(img);
}
img.src = _URL.createObjectURL(file);
}
</script>
ito code ko:
<div class="mt-3">
<label for="formFile" class="form-label ">Upload Image</label>
<input class="form-control" type="file" name="profile-pic" onchange ="displayPreview(this.files)" id="formFile">
</div>
<center>
<span id="preview"></span>
</center>
<hr class="my-4">
<button class="w-100 mb-2 btn btn-sm btn-lg rounded-3 btn-primary" name= "update" type="submit">Update</button>
</div>
</div>
</form>
<?php
$target_dir = "../photo_folder/";
$uploadErr = "";
if (isset($_POST["update"])){
$target_file = $target_dir . "/" . basename($_FILES["profile-pic"]["name"]);
$uploadOk = 1;
if(file_exists($target_dir)) {
$target_file = $target_dir . rand(1,9) . rand(1,9) . rand(1,9) . rand(1,9) . "_" .basename($_FILES["profile-pic"]["name"]);
$uploadOk = 1;
}
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if($_FILES["profile-pic"]["size"] > 5000000000000000000 ) {
$uploadErr = "Sorry, your file is too large";
$uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
$uploadErr = "Sorry, only JPG, PNG, JPEG and GIF files are allowed";
$uploadOk = 0;
}
if($uploadOk == 1) {
if (move_uploaded_file($_FILES["profile-pic"]["tmp_name"], $target_file)){
echo "the file has been uploaded";
}else {
echo "sorry , there was an error uploading file.";
}
}
}
?>
<span class="error"><?php echo $uploadErr; ?></span>
<script type = "application/javascript">
var _URL = window.URL || window.webkitURL;
function displayPreview(files){
var file = files[0];
var img = new Image();
var sizeKB = file.size / 1024;
img.onload =function(){
$(img).addClass('resized-image');
$('#preview').append(img);
}
img.src = _URL.createObjectURL(file);
}
</script>