我正在尝试编写一个简单的脚本,该脚本允许我将不同类型的媒体上传到 Web 服务器,其中包括当前的视频和照片格式。我遇到的问题是当我尝试上传视频时,页面上的表单似乎无法提交。就像我单击提交按钮一样,页面会挂起片刻,然后返回到显示的表单,就像未提交一样。
我试图增加 $max_file_size 中的 fileszie 但这没有任何效果,它似乎没有达到使用它的地步。
我也在互联网上搜索过,它建议我使用代码顶部列出的“ini_set”功能来排除任何 PHP 表单提交问题——这些似乎没有效果。
<?php
ini_set('upload_max_filesize', '45M');
ini_set('post_max_size', '45M');
ini_set('max_input_time', 30000);
ini_set('memory_limit', '45M');
$file_types_array=array("avi", "JPG", "jpeg", "flv", "mpeg", "FLV");
// File Size maximum set in bytes
$max_file_size=35645847;
// Test directory created on the server to allow for uploads
// potential to direct to user spercific areas for secuirty concerns
$upload_dir="uploads\\";
// Holds Unix Time in seconds, used for a unique stamp per upload to
// avoud multiple images/videos having the same ID
$stamp = time();
// Unique User ID - 123 for testing
$UserID = 123;
/* If the form is not submitted, display the form */
if(!isset($_POST["submitted"])){
$form = "<form action='' method='post' enctype='multipart/form-data'>Upload files:<br /><input type='hidden' name='submitted' value='TRUE' id='".time()."'><input type='hidden' name='MAX_FILE_SIZE' value='".$max_file_size."'>";
$form .= "<input type='file' name='file[]'><br />";
$form .= "<input type='submit' value='Upload'><br />Valid file type(s): ";
// Displays the valid file types set in $file_types_array
for($x=0;$x<count($file_types_array);$x++){
if($x<count($file_types_array)-1){
$form .= $file_types_array[$x].", ";
}else{
$form .= $file_types_array[$x].".";
}
}
$form .= "</form>";
echo($form);
}else{
foreach($_FILES["file"]["error"] as $key => $value){
if($_FILES["file"]["name"][$key]!=""){
if($value==UPLOAD_ERR_OK){
$fileID = $_FILES["file"]["name"][$key];
$filename = explode(".", $_FILES["file"]["name"][$key]);
$filenameext = $filename[count($filename)-1];
// Checks for file extension
$file_ext_allow = FALSE;
for($x=0;$x<count($file_types_array);$x++){
if($filenameext==$file_types_array[$x]){
$file_ext_allow = TRUE;
}
}
if($file_ext_allow){
if($_FILES["file"]["size"][$key]<$max_file_size){
$fileWrite = $UserID."_".$stamp.".".$filenameext;
if(move_uploaded_file($_FILES["file"]["tmp_name"][$key], $upload_dir.$fileWrite)){
echo("File uploaded successfully.<br />");
}else{ // Catch for unprepared error
echo($fileID." was not successfully uploaded<br />");
}
}else{ // Catch for File Size too big
echo($fileID." was too big, not uploaded<br />");
}
}else{ // Catch for bad File Name
echo($fileID." had an invalid file extension, not uploaded<br />");
}
}else{ // Successful Output
echo($fileID." was not successfully uploaded<br />");
}
}
}
}
?>
任何关于这个主题的帮助将不胜感激,因为我已经盯着这段代码太久了......
问候,