无法使用PHP将文件上传到文件夹

沙爹

我正在尝试使用PHP将文件上传到文件夹中,但无法完成。我的代码如下。

user.php:

$target_dir = "admin/uploads/";
$target_file = $target_dir . basename($_FILES['file']['name']);
$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
$uploadOk = 1;
$check = getimagesize($_FILES['file']['tmp_name']);
header('Content-Type: application/json');  
if ($check !== false) {  

  $uploadOk = 1;
} else {  

  $uploadOk = 0;
}

if (file_exists($target_file)) {  
    $uploadOk = 0;
}
            if ($uploadOk == 0) {  
            } else {
              if (move_uploaded_file($_FILES['file']['tmp_name'], $target_file)) {  
                $result['msg'] = "Image has uploaded successfully.";
                $result['num'] = 1;
                $result['img'] =$_FILES['file']['name'];
              } else {
                $result['msg'] = "Sorry, Your Image could not uploaded to the directory.";
                $result['num'] = 0;
   }

}

我收到消息了Sorry, Your Image could not uploaded to the directory.在这里,我得到的输入$_FILES如下。

$_FILES=array('file'=>array('name' => 'IMG-20161121-WA0000.jpg','type' => ' application/octet-stream','tmp_name' => '/tmp/phpSb6a53', 'error' => 0, 'size' => 119198));

我也有文件夹写权限。我的目录结构如下。

root folder

    ->admin
       =>uploads//(images need to saved)


    -> API
        =>V1
           ->user.php(//here is my file upload code)

在这种情况下,我始终无法将文件上传到文件夹中。

学习者

更改$targetdir为:

$targetdir = '../../admin/uploads';

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章