【发布时间】:2017-06-28 08:38:50
【问题描述】:
我已经检查了 php.ini 文件上传是否开启。 以下是代码请帮助我。 文件未上传到文件夹图像中。 我不知道代码有什么问题。 问题不在查询中,因为 (!empty($_FILES["uploadedimage"]["name"])) 不上传图片。
<form enctype="multipart/form-data" method="post">
<th><input style=" width:100px; font-size:13px" name="op" Placeholder="Operator Name"/></th>
<th> <input class="file-upload-input" type="file" name="uploadedimage"></th>
<th> <input class="btn btn-danger" type="submit" name="uploadnow" value="SUBMIT" class="theme-btn btn-style-one"></th>
</tr></form>
<?php
function GetImageExtension($imagetype)
{
if(empty($imagetype)) return false;
switch($imagetype)
{
case 'image/bmp': return '.bmp';
case 'image/gif': return '.gif';
case 'image/jpeg': return '.jpg';
case 'image/png': return '.png';
default: return false;
}
}
if (!empty($_FILES["uploadedimage"]["name"])) {
$file_name=$_FILES["uploadedimage"]["name"];
$temp_name=$_FILES["uploadedimage"]["tmp_name"];
$imgtype=$_FILES["uploadedimage"]["type"];
$ext= GetImageExtension($imgtype);
$imagename=date("d-m-Y")."-".time().$ext;
$target_path = "images/".$imagename;
if($_POST['uploadnow'])
{
$op=$_POST['op'];
if(move_uploaded_file($temp_name, $target_path)) {
$sql="INSERT INTO operator(op,mono) VALUES('".$op."','".$target_path."') ";
mysql_query($sql) or die
("error in $query_upload == ----> ".mysql_error());
}
}
?> <script type="text/javascript">
document.location.href='operator.php';
</script>
<?php
}
?>
【问题讨论】:
-
数据是否保存在db中
-
您的代码似乎正确。请检查文件夹权限。
标签: php