サーバーに PDF をアップロードする際に問題が発生しています。upload_max_filesize は 2M で、ファイルはそれ以上で、約 4M です。ここで私と同様の問題を持つ投稿を見つけました
$_FILE 大きなファイルをアップロードすると、upload_max_size がファイル サイズよりも大きい場合でもエラー 1 が返される
ini_set コマンドを正しく使用するために php.net から収集できるのは、現在使用しているこれです。
ini_set('upload_max_filesize', 100000000);
ini_set('post_max_size', 110000000);
ini_set('memory_limit', 120000000);
ini_set('max_input_time', 20);
しかし、私が投稿したリンクでは、彼らは別の方法を使用しているようです (正しいコードを要約しているだけでない場合)。しかし、私のコードもそのままでは機能していないようです。ページの下部に<?php phpinfo(); ?>
、upload_max_filesize がまだ 2M であると表示されています。ini_set の正しい構文を使用していますか? または、私のpdfをアップロードする際の問題は別のものですか?
アップロードを処理する私のコードは
//======================pdf upload=====================
if ($_POST['erasePDF'] == "Yes") //checking if erase box was checked and erasing if true
{
if (file_exists($pdf))
{
unlink( $pdf );
$pdf = "";
}
}
print_r($_FILES['pdf']);
if (!empty($_FILES['pdf']['name'])) //checking if file upload box contains a value
{
$saveDirectoryPDF = 'pdfs/'; //name of folder to upload to
$tempName = $_FILES['pdf']['tmp_name']; //getting the temp name on server
$pdf = $_FILES['pdf']['name']; //getting file name on users computer
$test = array();
$test = explode(".", $pdf);
if((count($test) > 2) || ($test[1] != "pdf" && $test[1] != "doc" && $test[1] != "docx")){
echo "invalid file";
}else{
$count = 1;
do{
$location = $saveDirectoryPDF . $count . $pdf;
$count++;
}while(is_file($location));
if (move_uploaded_file($tempName, $location)) //Moves the temp file on server
{ //to directory with real name
$pdf = $location;
}
else
{
echo "hi";
echo '<h1> There was an error while uploading the file.</h1>';
}
}
}else{
$pdf = "";
}
if(isset($_POST['link']) && $_POST['link'] != ""){
$pdf = $_POST['link'];
}
//======================end of pdf upload==============
行 'print_r($_FILES['pdf']);' の出力 は
Array ( [name] => takeoutmenu.pdf [type] => [tmp_name] => [error] => 1 [size] => 0 )