【问题标题】:unexpected 'if' (T_IF), expecting ',' or ';'意外的 'if' (T_IF),期待 ',' 或 ';'
【发布时间】:2015-02-09 12:39:46
【问题描述】:

我正在尝试为私有云存储系统创建一个安全的多文件上传脚本。我不知道我所做的有什么好处,因为我在 3 周前开始学习 php。

我在第 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

【问题讨论】:

  • echo('File mime type not accepted') 后缺少分号
  • 请发布您收到的错误消息:-)

标签: php file-upload syntax-error


【解决方案1】:

echo('File mime type not accepted') 之后的第 55 行缺少分号,而且第 58 行还有一个分号,不应该存在。

你应该删除 if 语句后的所有分号。

【讨论】:

  • 不知道;if 之后的@lol.. 奇怪的语法。应该删除imo
【解决方案2】:

echo('File mime type not accepted') 上面的行后面缺少一个分号

【讨论】:

    【解决方案3】:

    if 末尾有一个;

    它不应该在那里。

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

    你通常应该使用正确的if用法

    if (...)
    {
    }
    

    没有; 或没有{ } 的东西,即使只有1 行。

    【讨论】:

    • if 语句后可以有分号。它没有意义,但不会导致错误。
    【解决方案4】:

    您不仅在第 55 行缺少分号,而且还在第 58 行添加了多余的分号,其中应该有 {

    【讨论】:

      【解决方案5】:

      你的问题本身就有解决方案

       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))
      

      不需要分号。请使用一个好的代码编辑器来突出这些语法错误。这比发布问题并获得更多反对票要好。

      【讨论】:

        猜你喜欢
        • 2011-07-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-02
        • 2016-04-11
        • 1970-01-01
        • 2015-05-10
        相关资源
        最近更新 更多