Php 上传文件功能是否在linux中工作,但在Windows中不工作

Php 上传文件功能是否在linux中工作,但在Windows中不工作,php,ajax,file-upload,Php,Ajax,File Upload,代码 if(is_array($_FILES) && isset($_FILES['photography_attachment'])) { if(is_uploaded_file($_FILES['photography_attachment']['tmp_name'])) { $fileName = $_FILES["photography_attachment"]["name"]; // The file name $fileTm

代码

if(is_array($_FILES) && isset($_FILES['photography_attachment'])) {
      if(is_uploaded_file($_FILES['photography_attachment']['tmp_name'])) {
        $fileName = $_FILES["photography_attachment"]["name"]; // The file name
        $fileTmpLoc = $_FILES["photography_attachment"]["tmp_name"]; // File in the PHP tmp folder
        $fileType = $_FILES["photography_attachment"]["type"]; // The type of file it is
        $fileSize = $_FILES["photography_attachment"]["size"]; // File size in bytes
        $fileErrorMsg = $_FILES["photography_attachment"]["error"]; // 0 = false | 1 = true
        $kaboom = explode(".", $fileName); // Split file name into an array using the dot
        $fileExt = end($kaboom); // Now target the last array element to get the file extension

        if (!$fileTmpLoc) { // if file not chosen
          $error = $error."<p>Please browse for a file before clicking the upload button.</p>";
        } else if($fileSize > 10485760) { // if file size is larger than 2 Megabytes
          $error = $error."<p><span>Your file was larger than</span> 10 <span>Megabytes in size</span>.</p>";
          unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
        } else if (!preg_match("/.(gif|jpg|png|jpeg)$/i", $fileName) ) {
          // This condition is only if you wish to allow uploading of specific file types
          $error = $error."<p>Your file was not .gif, .jpg, .png</p>";
          unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
        } else if ($fileErrorMsg == 1) { // if file upload error key is equal to 1
          $error = $error."<p>An error occured while processing the file. Try again.</p>";
        }
     }else{ $error = "Please try again !!!"; }
  }else{ $error = "Attachment field cannot be blank!"; }
if(is_数组($_文件)和&isset($_文件['photography_attachment'])){
如果(是上传的文件($文件['photography\u attachment']['tmp\u name'])){
$fileName=$\u FILES[“photography\u attachment”][“name”];//文件名
$fileTmpLoc=$\u FILES[“photography_attachment”][“tmp_name”];//PHP tmp文件夹中的文件
$fileType=$\u文件[“摄影”附件][“类型”];//文件的类型
$fileSize=$\u文件[“摄影”附件][“大小”];//文件大小(字节)
$fileErrorMsg=$_文件[“摄影_附件”][“错误”];//0=false | 1=true
$kaboom=explode(“.”,$fileName);//使用点将文件名拆分为数组
$fileExt=end($kaboom);//现在以最后一个数组元素为目标以获取文件扩展名
如果(!$fileTmpLoc){//如果未选择文件
$error=$error.“请在单击上载按钮之前浏览文件。

”; }else if($fileSize>10485760){//如果文件大小大于2 MB $error=$error。“您的文件大小超过了10兆字节。

”; 取消链接($fileTmpLoc);//从PHP临时文件夹中删除上载的文件 }如果(!preg_匹配(/(gif | jpg | png | jpeg)$/i“,$fileName)){ //此条件仅在您希望允许上载特定文件类型时适用 $error=$error。“您的文件不是.gif、.jpg、.png

”; 取消链接($fileTmpLoc);//从PHP临时文件夹中删除上载的文件 }else if($fileErrorMsg==1){//如果文件上载错误键等于1 $error=$error。“处理文件时出错。请重试。

”; } }否则{$error=“请再试一次!!!”;} }else{$error=“附件字段不能为空!”;}
在windows中上载图像时,始终转到“请重试!!!”其他选项,但在linux系统中效果良好


你能帮我解决这个问题吗?

在windows平台上,你不能用“/”替换文件路径中的“\”

像这样:

$file = str_replace ("\\", "/", $_FILES['photography_attachment']['tmp_name']);
if(is_uploaded_file($file)) {
   [...]
}
或者对所有系统使用php内置方法:

$file = realpath($_FILES['photography_attachment']['tmp_name']);
if(is_uploaded_file($file)) {
   [...]
}

如果逻辑成功,上面的代码对上传的文件没有任何作用$_文件响应=>[photography_attachment]=>数组([name]=>ttest.jpg[type]=>[tmp_name]=>[error]=>1[size]=>0)@AD7six我使用以下答案(Richard answers)@BhAvikGajjar cool(如果是真的,似乎不太可能)修复了我的问题-在评论中粘贴不同且无关的错误对您没有帮助。