Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php文件上传脚本不会上传jpeg?_Php_Upload_Png_Jpeg - Fatal编程技术网

Php文件上传脚本不会上传jpeg?

Php文件上传脚本不会上传jpeg?,php,upload,png,jpeg,Php,Upload,Png,Jpeg,我有一个上传脚本,我借用并更改了一些位,回声被注释掉,因为最终输出是pdf 我有两个问题,第一个是很重要的,为什么它不允许我上传.jpeg?我可以上传.png和.jpg好吗 $target_dir = "../uploads/"; $target_file = $target_dir . basename($_FILES["brakeTestPic"]["name"]); $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_fi

我有一个上传脚本,我借用并更改了一些位,回声被注释掉,因为最终输出是pdf

我有两个问题,第一个是很重要的,为什么它不允许我上传.jpeg?我可以上传.png和.jpg好吗

$target_dir = "../uploads/";
$target_file = $target_dir . basename($_FILES["brakeTestPic"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["brakeTestPic"]["tmp_name"]);
    if($check !== false) {
        //echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        //echo "File is not an image.";
        $uploadOk = 0;
    }
}
// Check if file already exists
if (file_exists($target_file)) {
    //echo "Sorry, file already exists.";
    $uploadOk = 0;
}
// Check file size
if ($_FILES["brakeTestPic"]["size"] > 5000000000000000) {
    //echo "Sorry, your file is too large.";
    $uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && 
    $imageFileType != "jpeg" && $imageFileType != "gif" ) 
{

    //echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
    $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    //echo "Sorry, your file was not uploaded.";
    // if everything is ok, try to upload file
} else {
    $temp = explode(".", $_FILES["brakeTestPic"]["name"]);
    $newfilename = round(microtime(true)) .'1'. '.' . end($temp);
    move_uploaded_file($_FILES["brakeTestPic"]["tmp_name"], $target_dir . 
    $newfilename);
    $braketestpiclocation = $target_dir . $newfilename;
};

编辑-我删除了第二个问题,它是重复的。

我运行了你的代码,一切正常。再次检查您正在上载的文件。此外,您还可以将检查文件格式的条件更改为:

if( ! in_array($imageFileType, ['jpg', 'jpeg', 'gif', 'png']) ) {

}
它更简单,可读性更强

来自$\u文件的我的数据:

Array ( 
   [brakeTestPic] => Array ( 
      [name] => Deski.JPEG 
      [type] => image/jpeg 
      [tmp_name] => /private/var/tmp/phpL8CKhq 
      [error] => 0 
      [size] => 21746
    )
)

请记住将enctype=“multipart/form data”添加到表单标签中。

这就是为什么每个问题只能问一个问题的原因。你的第二个问题有一个obvoius duplicate,那么我现在如何删除none-duplicate位呢?我只是想得到一些帮助,不是网络警察?好吧,我重新开始这个问题