2

我在这里查看了其他五个类似的问题,但没有一个能够解决我的问题。我正在上传一个 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,该文章没有导致任何问题得到修复。任何人都可以看到有什么问题或给我一些提示吗?

4

2 回答 2

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");
于 2012-05-19T22:16:12.197 回答
0

在与托管服务提供商的技术人员多次交流后,他们设法为该文件夹授予了正确的权限(我之前尝试过 0777,但没有成功)。我相信一些伏都教在幕后进行,但这是No errors in the error_log; I have set 777 permissions on /home/x/up脚本开始工作的。

于 2012-05-20T00:50:44.377 回答