2015-09-22 225 views
-2

我得到的举动上传文件这个错误解析错误:语法错误,意外

解析错误:语法错误,意想不到的“[”

我的PHP代码是

function up_file($path, $files) 
    { 
     $valid_formats = array("jpg", "png", "gif", "zip", "bmp", "PNG"); 
     $max_file_size = 1024*500; //100 kb  
     $count = 0; 

    // Loop $_FILES to exeicute all files 
    foreach ($files['files']['name'] as $f => $name) 
    {  
     if ($files['files']['error'][$f] == 4) 
     { 
      continue; // Skip file if any error found 
     }   
     if ($files['files']['error'][$f] == 0) 
     {    
      if ($files['files']['size'][$f] > $max_file_size) 
      { 
       $message[] = "$name is too large!."; 
       continue; // Skip large files 
      } 
      elseif(! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats)) 
      { 
       $message[] = "$name is not a valid format"; 
       continue; // Skip invalid file formats 
      } 
      else 
      { 

       if(move_uploaded_file($files["files"]["tmp_name"][$f], $path.$count.'.'.explode('.',$name)[1])) 
       echo $_FILES; 
       $count++; // Number of successfully uploaded file 


      } 
     } 
    }    
} 

我能够得到文件的路径也$ F有值为零,但实际的问题是在这行代码

if(move_uploaded_file($files["files"]["tmp_name"][$f], $path.$count.'.'.explode('.',$name)[1])) 

I H AVE给予的权限也到文件夹我知道爆炸在PHP 6已经过时,但现在我在PHP 5.3

+0

爆炸从来没有过时。而PHP 6是不行的。 – Amarnasan

回答

0

explode('.',$name)[1]不工作PHP 5.3

$name_extension = explode('.',$name); 
if (move_uploaded_file($files["files"]["tmp_name"][$f], $path.$count.'.'.$name_extension[1])) { 
    //do something 
} 
相关问题