无法上传.mpg文件

时间:2011-08-17 14:48:50

标签: php html file-upload

我在PHP中构建了一个相当简单的文件上传器。到目前为止,我没有上传图像和zip文件的麻烦。但是,我似乎无法上传.mpg的。每当我尝试它然后挂了片刻后,页面似乎没有尝试上传任何东西。例如:这个

// This is also manually set in php.ini
ini_set("upload_max_filesize", "524288000");
...
print_r($_FILES);
print_r($_POST); // I'm sending along one variable in addition to the file

只返回空数组。为了完整起见,这是前端

<form action="uploadVideo.php" method="post" enctype="multipart/form-data">
        <input type="hidden" name="MAX_FILE_SIZE" value="524288000"/>
        <input type="hidden" name="extravar" value="value" />
        <p>
            <label for="file">Filename:</label>
            <input type="file" name="file" id="file" /><br />
            <i>Accepted formats: .mp4, .3gp, .wmv, .mpeg and .mpg. Cannot exceed 500MB.</i>
        </p>
        <p>Description:</p>
            <textarea name="description" rows="4" cols="40"></textarea>
        <p><input type="submit" name="submit" value="Submit" /></p>
    </form>

我正在测试的文件只有33MB,我测试了一个类似大小的.wmv,上传得很好。

编辑:下面列出的整个PHP文件

<?php
// Ensure that the user can upload up to the maximum size
ini_set("upload_max_filesize", "524288000");
ini_set("post_max_size", "524288000");
print_r($_POST);
print_r($_FILES);

if(!$link = mysql_connect($SERVER_LOCATION, $DB_USER, $DB_PASS)) die("Error connecting to server.");
mysql_select_db($DB_NAME);
$eventID = $_POST['event'];

// Select the event this is associated with
$query = "SELECT eventName FROM event WHERE eventID = $eventID";
if(!$res = mysql_query($query, $link)) die("Error communicating with database.");
$path = mysql_fetch_row($res);
$path = "media/$path[0]";

// If this event doesn't have a media folder, make one
if(!file_exists($path)) {
    mkdir($path);
}

// If this event doesn't have a GIS subfolder, make one
$path = "$path/videos";
if(!file_exists($path)) {
    mkdir($path);
}

// Generate todays date and a random number for the new filename
$today = getdate();

$seed  = $today['seconds'] * $today['minutes'];
srand($seed);
$random = rand(0, 999);

$today = $today['mon']."-".$today['mday']."-".$today['year'];

$fileType = $_FILES["file"]["type"];
$fileExtension = pathinfo($_FILES["file"]["name"], PATHINFO_EXTENSION);

$isMP4 = ($fileType == "video/mp4" && $fileExtension == "mp4");
$isWMV = ($fileType == "video/x-ms-wmv" && $fileExtension == "wmv");
$isMPG = ($fileType == "video/mpeg" && ($fileExtension == "mpeg" || $fileExtension == "mpg"));
$is3GP = ($fileType == "video/3gp" && $fileExtension == "3gp");
$sizeIsOK = ($_FILES["file"]["size"] < 524288000);

if( ($isMP4 || $isWMV || $isMPG || $is3GP) && $sizeIsOK ) {
    if($_FILES["file"]["error"] > 0) {
        echo "<p>There was a problem with your file. Please check that you submitted a valid .zip or .mxd file.</p>";
        echo "<p>If this error continues, contact a system administrator.</p>";
        die();
    } else {
        // Ensure that the file get's a unique name
        $filename = $today . "-" . $random . "." . $fileExtension;
        while(file_exists("$path/$filename")) {
            $random = rand(0, 999);
            $filename = $today . "-" . $random . "." . $fileExtension;
        }
        move_uploaded_file($_FILES["file"]["tmp_name"], "$path/$filename");

        $description = $_POST['description'];
        $query = "INSERT INTO media (eventID,FileName,File,filetype,Description) VALUES ($eventID,'$filename','$path','video','$description')";
        if(!$res = mysql_query($query, $link))
            echo "<p>Error storing file description. Please contact a system administrator.</p>";
        else {
            echo "<h3>File: <i>".$_FILES["file"]["name"]."</i></h3>";
            if(strlen($description) > 0) {
                echo "<h3>Description: <i>".$description."</i></h3>";
            }
            echo "<p><strong>Upload Complete</strong></p>";
        }
        echo "<button onclick=\"setTimeout(history.go(-1), '1000000')\">Go Back</button>";
    }
} else {
    echo "<p>There was a problem with your file. Please check that you submitted a valid .zip or .mxd file.</p>";
    echo "<p>If this error continues, contact a system administrator.</p>";
}
?>

2 个答案:

答案 0 :(得分:0)

好的,我首先想知道文件大小的问题,但是这个大小的其他文件正如你所写的那样工作。

但是只是确实得到了它不是文件大小的问题:

当您提升最大文件大小时,您还必须提高最大帖子大小:post_max_size

答案 1 :(得分:0)

您无法使用上传到的脚本中的ini_set()来调整文件上传限制 - 在上传完成之后脚本才会执行,因此无法执行ini_set()覆盖。 PHP中的默认参数将使用下限,如果超过系统upload_max_filesize,将终止上载。

您需要在PHP中的.ini级别覆盖,或通过.htaccess文件中的php_value指令覆盖。这些将在上传开始时改变PHP的设置。