我在这里查看了其他五个类似的问题,但没有一个能够解决我的问题。我正在上传一个 1657 字节大小的 CSV 文件。
这是我的 php.ini 文件中的一些值
upload_max_filesize = 2M
post_max_size = 8M
$file = $_FILES['csv'];
if (!isset($file)) {
halt(HTTP_NOT_FOUND, 'This page could not be found on the web server');
}
if (substr(strrchr($file['name'], '.'), 1) != 'csv') {
halt(500, 'Sorry but please upload a CSV file next time!');
}
if ($file['error'] != '0') {
die('An error occurred during upload.<br />Error: ' . $file['error']);
}
$file_loc = '/home/x/tmp/up/' . basename($file['tmp_name']) . '.csv';
if (file_exists('/home/x/tmp/up/')) {
echo 'the directory exists....<br/>';
}
if (file_exists($file['tmp_name'])) {
echo 'tmp file exists<br/>';
echo filesize($file['tmp_name']) . 'b<br/>';
}
if (move_uploaded_file($file['tmp_name'], $file_loc)) {
echo 'Uploaded to: ' . $file_loc;
} else {
echo 'something went wrong!' . print_r($_FILES['csv'], true);
echo '<br />Upload Max Size: ' . ini_get('upload_max_filesize');
echo '<br />POST Max Size: ' . ini_get('post_max_size');
}
这是我上传文件时生成的输出:
the directory exists....
tmp file exists
1657b
something went wrong!Array ( [name] => hm.csv [type] => application/vnd.ms-excel [tmp_name] => /tmp/php72p1VP [error] => 0 [size] => 1657 )
Upload Max Size: 2M
POST Max Size: 8M
我已经在“常见陷阱”文章下查看了 PHP.net,该文章没有导致任何问题得到修复。任何人都可以看到有什么问题或给我一些提示吗?