Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php将excel文件保存到服务器_Php_Excel_Export_Export To Excel - Fatal编程技术网

使用php将excel文件保存到服务器

使用php将excel文件保存到服务器,php,excel,export,export-to-excel,Php,Excel,Export,Export To Excel,我正在从数据库中检索数据并用下面的代码将其导出到excel,从这里我可以导出到excel并从浏览器保存文件 $sql_select= "my query"; $queryRes = mysql_query($sql_select); $header = "Country" . "\t"; $header .= "Network" . "\t"; $header .= "MCC" . "\t"; $header .= "MNC" . "\t"; $header .= "ClientPrice"

我正在从数据库中检索数据并用下面的代码将其导出到excel,从这里我可以导出到excel并从浏览器保存文件

$sql_select= "my query";
$queryRes = mysql_query($sql_select);

$header = "Country" . "\t";
$header .= "Network" . "\t";
$header .= "MCC" . "\t";
$header .= "MNC" . "\t";
$header .= "ClientPrice" . "\t";
$header .= "Currency" . "\t";

$data = '';
while( $row = mysql_fetch_assoc($queryRes)){
$row1 = array();
$row1[] = $row['country'];
$row1[] = $row['networkname'];
$row1[] = $row['mcc'];
$row1[] = $row['mnc'];
$row1[] = $row['clientprice'];
$row1[] = $row['currency'];
$data .= join("\t", $row1)."\n";
//$data= $first_name."\t";
//$data .= $row['originator']."\t";
}

header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=expot.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data"; 
exit(); 
我正在使用以下代码将excel文件保存到此位置“/pricelists/example.xls”

它正在显示警告

Warning: file_put_contents(/pricelists/example.xls) [function.file-put-contents]: failed to open stream:

有人能告诉我如何解决这个问题吗?

路径/pricelists/example.xls中是否存在您的文件

使用文件的相对路径可以解决此问题

file_put_contents("pricelists/example.xls",$data);
如果您使用Windows:

转到包含输出文件的文件夹的“属性”,禁用只读,转到“安全”索引,单击“编辑”,然后单击“添加”,键入“Everyone”,授予完全权限并应用设置

如果您使用Linux或租用了Web服务器:


使用CHMOD 777/您的/文件夹/或您的FTP应用程序授予完全权限。

否,它不存在。如果文件不存在,函数“file\u put\u contents”应该创建该文件。如果您试图将该文件保存到一个目录中,而该目录中的file\u put\u contents()没有写入权限,例如
/pricelists
(请记住这是来自文件系统根目录-
/
),您希望它忽略这些权限并仍然写入文件吗?如果目录不存在,是否创建该目录?-什么价格安全性?此文件夹“pricelists”的权限为777@arok-是的,这一切都很好,但是您是否希望在您的网站或文件系统的根目录中写入名为
pricelists
的文件夹?
file_put_contents("pricelists/example.xls",$data);