2015-02-09 46 views
-3

我正在嘗試爲私有云存儲系統創建安全的多文件上傳腳本。我不知道我做了什麼是好的,因爲我在3周前開始學習php。意想不到的'if'(T_IF),期待','或';'

我一直收到第59行的錯誤:if(move_uploaded_file($_FILES['file']['tmp_name'], $upload_dir)); 我不知道我哪裏出錯了。如果有人能幫助我,那會很棒。

這是我的HTML

<form enctype="multipart/form-data" action="PHP/Click_Upload.php" method="POST"> 
<input type="hidden" name="MAX_FILE_SIZE" value="1000000000000" /> 
Send this file: <input id="userfile" type="file" /> 
<input type="submit" value="Send File" /> 
</form> 

這是我的PHP

<?php 
// Folder for upload files 
$upload_dir = "../../SeagateHDD/Uploads"; 

//allowed file extensions 
$allowed_types = array(
/* images extensions */ 
'jpeg', 'bmp', 'png', 'gif', 'tiff', 'jpg', 
/* audio extensions */ 
'mp3', 'wav', 'aac', 'wma', 'm4a', 
/* movie extensions */        
'mov', 'flv', 'mpeg', 'mpg', 'mp4', 'avi', 'wmv', 
/* document extensions */        
'txt', 'pdf', 'ppt', 'pps', 'xls', 'doc', 'xlsx', 'pptx', 'ppsx', 'docx' 
         ); 

//Mime types not accectped 
$mime_type_black_list= array(
/* Audio Mime Types */ 
'audio/basic', 'audio/L24', 'audio/ogg', 'audio/opus', 'audio/vorbis', 
'audio/vnd.rn-realaudio', 'audio/vnd.wave', 'audio/webm', 'audio/example', 
/* Images Mime Type */ 
'image/vnd.djvu', 'image/example', 
/* Message Mime Type*/ 
'message/http', 'message/imdn+xml', 'message/partial', 'message/rfc822', 
'message/example', 
/* 3D Model Mime Type*/ 
'model/iges', 'model/mesh', 'model/vrml', 'model/x3d+binary', 
'model/x3d+fastinfoset', 'model/x3d-vrml','model/x3d+xml', 'model/example' 
          ); 
//checks 
if(isset($_FILES['submit'])){ 

//loop thought all the files 
foreach ($_FILES ['submit']['tmp_name'] as $key => $tmp_name) { 
    $file_name = $_FILES['files']['name'][$key]; 
    $file_size = $_FILES['files']['size'][$key]; 
    $file_type = $_FILES['files']['type'][$key]; 
    $file_tmp = $_FILES['files']['tmp_name'][$key]; 

//check files are not bigger than 100MB 
if ($file_size > 100000000){ 
     echo('File size must be less than 100MB'); 
} 

// convert file name to lowercase and explode the file and look at the extension 
$file_ext=strtolower(end(explode('.', $_FILES['file']['name'][$key]))); 

//check to see if file extension is accpeted 
if(in_array($file_ext, $allowed_types)=== false); 
    echo('File extension not accepted'); 

//check files with mime types 
if(in_array($file_ext, $mime_type_black_list)=== true); 
    echo('File mime type not accepted') 

//move files from temp to choosen directory 
if(move_uploaded_file($_FILES['file']['tmp_name'], $upload_dir)); 
    { 
    echo ("File Uploaded"); 
    } 
    else { 
    echo "Sorry, there was a problem uploading your file."; 
    } 
    } 
} 

<?php 
+0

'echo('File mime type not accepted')後面缺少分號:) – 2015-02-09 12:41:49

+0

請發佈您收到的錯誤消息:-) – 2015-02-09 12:47:04

回答

2

你錯過了上線55分號echo('File mime type not accepted')後,你也有上線58一個分號,那不應該在那裏。

您應該刪除if語句後的所有分號。

+0

不知道'if'後面'''大聲笑......奇怪句法。應該刪除imo – DanFromGermany 2015-02-09 12:45:17

1

你缺少的行之後分號上述echo('File mime type not accepted')

+0

然後下一個問題是DanFromGermany說的。 – trex005 2015-02-09 12:43:44

0

您在if年底有;

它不應該存在。

if(move_uploaded_file($_FILES['file']['tmp_name'], $upload_dir)); 
{ 
    // ... 
} 

通常你應該即使只有1中的情況下線上使用正確的,如果使用

if (...) 
{ 
} 

不是與;或不{ }

+1

if語句後可以有分號。這沒有意義,但它不會導致錯誤。 – 2015-02-09 12:42:07

0

你不僅缺少線55分號,但也增加了在第58行冗餘一個本來應該有{

0

你的問題本身所具有的解決方案

unexpected 'if' (T_IF), expecting ',' or ';' 

意味着你已經錯過了一個分號。

if(in_array($file_ext, $mime_type_black_list)=== true); 
    echo('File mime type not accepted'); 

if(move_uploaded_file($_FILES['file']['tmp_name'], $upload_dir)) 

不需要一個分號。請使用一個好的代碼編輯器來突出顯示這些語法錯誤。這比發佈問題並得到更多的選票更好。

相關問題