简体   繁体   English

PHOP标头 - 从PHP脚本打开CSV文件

[英]PHOP headers - Opening a CSV file from PHP script

I have the below code to open a CSV file, but for some reason it looks to be converting shopkeeper/89137.csv to shopkeeper_89137.csv . 我有下面的代码打开一个CSV文件,但由于某种原因它看起来是转换shopkeeper/89137.csvshopkeeper_89137.csv It keeps opening a blank csv file obviously because its looking for a file that isnt there. 它显然打开一个空白的csv文件,因为它寻找的文件不存在。 What is the proper way to reference a file in order to open it? 引用文件以打开文件的正确方法是什么?

            header("Content-type: text/csv");
            header("Content-Disposition: attachment; filename=shopkeeper/89137.csv");
            header("Pragma: no-cache");
            header("Expires: 0");

Referencing file paths is not ideal in the HTTP header. 在HTTP标头中引用文件路径并不理想。 You must reference only "89137.csv" for the filename, and then process your file by appending "shopkeeper/" to the filename in your file opening function. 您必须仅为文件名引用“89137.csv”,然后通过在文件打开功能中将“shopkeeper /”附加到文件名来处理您的文件。 Remember that you can still use variables in the header string parameter. 请记住,您仍然可以在头字符串参数中使用变量。

Actually, the / character is reserved and cannot be used as a filename!! 实际上, /字符是保留的,不能用作文件名!!

I would reconsider your naming scheme... 我会重新考虑你的命名方案......

The headers should only include the base name of the file being sent. 标头应仅包含要发送的文件的基本名称。 On the receiving end of things, it thinks you're trying to pass it a file with the name "shopkeeper/89137.csv" which, on most operating systems, contains an illegal character (/) for a file name, so it gets converted to an underscore. 在接收端,它认为你试图传递一个名为“shopkeeper / 89137.csv”的文件,在大多数操作系统上,它包含一个非法字符(/)作为文件名,所以它得到了转换为下划线。

You should probably tweak the line to read: 你应该调整一行来阅读:

header("Content-Disposition: attachment; filename=89137.csv");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM