【问题标题】:I am uploading an image using PHP ,but its not uploading into folder?我正在使用 PHP 上传图像,但它没有上传到文件夹中?
【发布时间】: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


【解决方案1】:

试试$target_path = "/images/".$imagename;

【讨论】:

  • 我检查了但不工作,请您重新检查代码
  • 代码看起来合法,尝试调试。尝试 echo "join" if (!empty($_FILES["uploadedimage"]["name"])) {
【解决方案2】:

尝试将这些行放在代码的顶部以显示所有 PHP 错误/警告并查看您得到的结果。

error_reporting(E_ALL);
ini_set('display_errors', 1);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-29
    • 2021-06-14
    • 2017-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-24
    • 2023-04-01
    相关资源
    最近更新 更多