上传.xls文件。

时间:2010-08-20 08:39:06

标签: php

这是我的代码:

<?php

require_once 'Excel/reader.php';

$data = new Spreadsheet_Excel_Reader();

move_uploaded_file($_FILES["file"]["tmp_name"],$_FILES["file"]["name"]);

$data->read($_FILES["file"]["name"]);


error_reporting(E_ALL ^ E_NOTICE);

echo "<table border='1'>";

echo "<tr><th>First Name</th><th>Middle Name</th><th>Last Name</th><th>Email ID</th></tr>";

for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++)
         {
echo "<tr>";


echo "<td>";

        echo $data->sheets[0]['cells'][$j+1][1];

echo "</td>";   

echo "<td>";    

        echo $data->sheets[0]['cells'][$j+1][2];

echo "</td>";


echo "<td>";


        echo $data->sheets[0]['cells'][$j+1][3];

echo "</td>";


echo "<td>";


        echo $data->sheets[0]['cells'][$j+1][4];

echo "</td>";

        //echo "<br>";


echo "</tr>";

        }


echo "</table>";


?>

这在localhost上正常运行,但是当我尝试在服务器上运行它时显示:

Warning: move_uploaded_file(Book1.xls) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/wingsele/public_html/get.php on line 6

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpufQkcr' to 'Book1.xls' in /home/wingsele/public_html/get.php on line 6

The filename Book1.xls is not readable

我错过了什么?

1 个答案:

答案 0 :(得分:2)

您需要将写入权限(chmod,可能使用您的FTP客户端)设置为您将上载文件移动到的目录。

另外,在这一行:

move_uploaded_file($_FILES["file"]["tmp_name"],$_FILES["file"]["name"]);

你应该指定一个完整的路径作为第二个参数,例如

   move_uploaded_file($_FILES["file"]["tmp_name"],dirname(__FILE__)."/".$_FILES["file"]["name"]);

用于当前目录。