这是我为页面的更新细节和图像编写的代码。这里我上传的文件在jpg和png格式只。但它显示:
抱歉,只允许png和png格式。
我呆在那里。我怎样才能克服这个问题?
<?php
include 'db.php';
$target_dir = "banners/";
$target_file = $target_dir . microtime() . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== true) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
if($imageFileType != "png" && $imageFileType != "jpg" && $imageFileType != "jpeg" && $imageFileType != "JPEG" && $imageFileType != "Jpeg" && $imageFileType != "PNG" && $imageFileType != "JPG") {
echo "Sorry, only PNG and JPG files are allowed.";
$uploadOk = 0;
}
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
} 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.";
}
}
if($_FILES["fileToUpload"]["name"]!=''){
$sql = "UPDATE `business_profile` SET `bs_name`='".$_POST['bsname']."',`bs_cat`='".$_POST['bscat']."',`mobile`='".$_POST['mobile']."',`email`='".$_POST['email']."',`location`='".$_POST['location']."',`addr`='".$_POST['addr']."',`image`='$target_file',`description`='".$_POST['desc']."' WHERE id='".$_POST['id']."'";
}else{
$sql = "UPDATE `business_profile` SET `bs_name`='".$_POST['bsname']."',`bs_cat`='".$_POST['bscat']."',`mobile`='".$_POST['mobile']."',`email`='".$_POST['email']."',`location`='".$_POST['location']."',`addr`='".$_POST['addr']."',`description`='".$_POST['desc']."' WHERE id='".$_POST['id']."'";
}
if (mysqli_query($conn, $sql)) { ?>
<SCRIPT LANGUAGE='JavaScript'>
window.alert('Profile Added Succesfully')
window.location.href='http://smartpuppies.in/admin/dashboard';
</SCRIPT>
<?php }else{ ?>
<SCRIPT LANGUAGE='JavaScript'>
window.alert('Error In adding , please try again. ')
window.location.href='http://smartpuppies.in/admin/dashboard';
</SCRIPT>
<?php }
?>
这是我的fo2rm。在这里,我有商业细节,如企业名称,分类,他们的商店形象和新形象的商店
<form class="form-horizontal form-label-left" action="http://smartpuppies.in/some" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label for="" class="control-label col-md-3 col-sm-3 col-xs-12">Business Name</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input class="form-control col-md-7 col-xs-12" name="bsname" value="<?php echo $row_req['bs_name']; ?>" type="text" required />
</div>
</div>
<!--<div class="form-group">
<label for="" class="control-label col-md-3 col-sm-3 col-xs-12">Business Category</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input class="form-control col-md-7 col-xs-12" name="bscat" value="<?php echo $row_req['bs_cat']; ?>" type="text" required/>
</div>
</div> --->
<input type="hidden" name="id" value="<?php echo $row_req['id']; ?>" />
<div class="form-group">
<label for="" class="control-label col-md-3 col-sm-3 col-xs-12">Phone No</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input class="form-control col-md-7 col-xs-12" name="mobile" value="<?php echo $row_req['mobile']; ?>" type="text"/>
</div>
</div>
<div class="form-group">
<label for="" class="control-label col-md-3 col-sm-3 col-xs-12">Email Id </label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input class="form-control col-md-7 col-xs-12" name="email" value="<?php echo $row_req['email']; ?>" type="text"/>
</div>
</div>
<div class="form-group">
<label for="" class="control-label col-md-3 col-sm-3 col-xs-12">Location</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input class="form-control col-md-7 col-xs-12" name="location" value="<?php echo $row_req['location']; ?>" type="text"/>
</div>
</div>
<div class="form-group">
<label for="" class="control-label col-md-3 col-sm-3 col-xs-12">Adress</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input class="form-control col-md-7 col-xs-12" name="addr" value="<?php echo $row_req['addr']; ?>" type="text"/>
</div>
</div>
<div class="form-group">
<label for="" class="control-label col-md-3 col-sm-3 col-xs-12">Home Delivery </label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input class="form-control col-md-7 col-xs-12" name="" value="<?php echo $row_req['del_option1']; ?>Rs,<?php echo $row_req['del_option2']; ?>Rs,<?php echo $row_req['del_option3']; ?>Rs" type="text" readonly/>
</div>
</div>
<div class="form-group">
<label for="" class="control-label col-md-3 col-sm-3 col-xs-12">Description </label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input class="form-control col-md-7 col-xs-12" name="desc" value="<?php echo $row_req['description']; ?>" type="text"/>
</div>
</div>
<div class="form-group">
<label for="" class="control-label col-md-3 col-sm-3 col-xs-12">Store Image</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<a href="http://www.smartpuppies.in/<?php echo $row_req['image'];?>" class="acustom" target="_blank"> Click Me </a>
</div>
</div>
<div class="form-group">
<label for="" class="control-label col-md-3 col-sm-3 col-xs-12">Upload Image</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="file" name="fileToUpload" class="margtopbottom"/>
</div>
</div>
<div class="text-center" >
<input name="submit" value="Update" type="submit"/>
</div>
</form>
1条答案
按热度按时间mdfafbf11#
更改以下内容
进入