我試圖創建一個應用程序,允許我上傳大於5MB的文件,但是我總是收到一個錯誤消息,說文件太大了。我修改了php.ini upload_max_filesize和post_max_size,並將其設置爲1GB,但沒有奏效。上傳的文件大於5MB
這是我的代碼:
if(is_uploaded_file($_FILES['pdf']['tmp_name'])&&($_FILES['pdf']['error'] == UPLOAD_ERR_OK)){
$file = $_FILES['pdf'];
$size = round($file['size']/10485760);
if($size > 10485760){
echo 'The uploaded file was to large.';
}
if(($file['type'] != 'application/pdf') && (substr($file['name'], -4) !='.pdf')){
echo 'The uploaded file was not a PDF.';
}
if(!array_key_exists('pdf', $add_pdf_errors)){
$tmp_name = sha1($file['name'].uniqid('', TRUE));
$dest = '../pdfs/'.$tmp_name.'_tmp';
if(move_uploaded_file($file['tmp_name'], $dest)){
$_SESSION['pdf']['tmp_name'] = $tmp_name;
$_SESSION['pdf']['size'] = $size;
$_SESSION['pdf']['file_name'] = $file['name'];
echo '<h4>The file has been uploaded!</h4>';
}else{
trigger_error('The file coul not be moved.');
unlink($file['tmp_name']);
}
}
}else{
switch ($_FILES['pdf']['error']){
case 1:
case 2:
echo 'The uploaded file was to large.';
break;
case 3:
echo 'The file was only partially uploaded.';
break;
case 6:
case 7:
case 8:
echo 'The file could not be uploaded to a system error.';
break;
case 4:
default:
echo 'No file was uploaded.';
break;
}
}
我怎樣才能解決這個問題呢?
做修改php.ini後重新啓動Apache? – keeg
$ size = round($ file ['size']/10485760);這有什麼用途? –
是的,但我仍然得到相同的錯誤 – aleczandru