我正在尝试使用PHP上传文件!我尝试上传PNG,JPG,PDF,TXT文件,这些上传仅在文件大小约为20kb时才有效.当我尝试上传大小约为150KB $_FILE error = 3
的文件时,会打印并且文件名允许说'1234.png',其中tmp_name为空,图像本身也是如此!这是我的代码
ini_set('display_errors',1); error_reporting(-1); $imageTmp = addslashes($_FILES['image']['tmp_name']); //$imageTmp = $_FILES['image']['tmp_name']; $imageOldName = addslashes($_FILES['image']['name']); $imageData = file_get_contents($imageTmp); //$imageData = base64_encode($imageTmp); echo 'image temp name: '. $imageTmp .' '; echo 'error: '. $_FILES['image']['error']. ' '; echo 'image name: '. $imageOldName. ' '; echo 'image data: '. $imageData. ' '; echo 'image type:'. $_FILES['image']['type']; echo ""; echo "POST:"; print_r($_POST); echo "FILES:"; print_r($_FILES); echo ""; $inipath = php_ini_loaded_file(); if ($inipath) { echo 'Loaded php.ini: ' . $inipath; } else { echo 'A php.ini file is not loaded'; }
我尝试了多种解决方案,例如更改32M 的值post_max_size = 200M
而upload_max_filesize = 200M
不是32M
这是尝试上传txt文件4KB的结果:
image temp name: /Applications/MAMP/tmp/php/phpOc7d6a error: 0 image Name: test.txt image data: hello image type:text/plain POST:Array ( [submit] => Record Test ) FILES:Array ( [image] => Array ( [name] => test.txt [type] => text/plain [tmp_name] => /Applications/MAMP/tmp/php/phpOc7d6a [error] => 0 [size] => 405 ) ) Loaded php.ini: /Applications/MAMP/bin/php/php5.6.10/conf/php.ini
上传PNG文件127KB的结果:
警告:file_get_contents():第10行上的path/test1.php中的文件名不能为空图像临时名称:错误:3图像名称:IMG_8807.JPG图像数据:图像类型:
POST:Array ( ) FILES:Array ( [image] => Array ( [name] => IMG_8807.JPG [type] => [tmp_name] => [error] => 3 [size] => 0 ) ) Loaded php.ini: /Applications/MAMP/bin/php/php5.6.10/conf/php.ini
顺便说一句,上传失败后,服务器崩溃并显示502网关,我必须重新启动Apache!