我在这里查看了其他五个类似的问题,但没有一个能够解决我的问题。我正在上传一个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,但没有导致任何修复。任何人都可以看到有什么问题或给我一些提示吗?
答案 0 :(得分:1)
以下提示可能会有所帮助。
1. The folder exists, check for spellings
2. Check the properties of the folder and make sure the permissions have read+write 0666
3. Make sure the file is within your public html root, otherwise double check the owner of the file, and make sure PHP Has read / write access to it.
4. Look for the logs i.e. Unable to move '/tmp/php6wlOg1' to 'upload/110216104651_00134_smooth_1440x900.jpg'
5. If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty. So set it according to your need.
还设置此项以查看是否存在任何错误
error_reporting(E_ALL); // or E_STRICT
ini_set("display_errors",1);
ini_set("memory_limit","1024M");
答案 1 :(得分:0)
在与托管服务提供商的技术人员进行多次交流后,他们设法为该文件夹提供了正确的权限(之前我曾尝试过0777但不起作用)。我相信一些伏都教在幕后进行,但这是No errors in the error_log; I have set 777 permissions on /home/x/up
并且脚本开始工作。