2014-02-26 90 views
0

我想改变服务器上的文件权限,我无法让它工作。我需要一些特定的文件,这些文件是.csv格式,需要在上传后读取。 Fopen无法打开文件,我认为这是权限问题。默认值是640,我需要它在777我得到的错误是:chmod和fopen无法正常工作

chmod() [function.chmod]: No such file or directory 
fopen(http://.../file.csv) [function.fopen]: failed to open stream: No such file or directory 

文件上传和FOPEN的路径是确定的,所以这不是一个问题。问题在于许可。所以,我试图去改变它槽PHP这样的:

$csv_file = $csvpath."import/".$typ."/".$id."/".$flname; // path to the csv file 
chmod($csv_file, 0777); 

我试着用相对和绝对路径仍然没有工作。安全模式关闭。任何帮助,将不胜感激。

回答

0

您正在尝试使用fopen一个http://文件,因此它抛出一个错误:failed to open stream.

你应该使用完整的服务器路径。

$csvFile = $csvpath."import/".$typ."/".$id."/".$flname; 
$filePath = realpath($csvFile); // also checks if the file exists! 
if (!$filePath || !is_file($filePath)) { 
    die('file not found: ' . $csvFile); 
} else { 
    fopen($filePath); 
} 
+0

仍然不能正常工作:/ – enigmaticus

+0

它不会因'文件未找到:'而死?和'fopen'仍然会抛出相同的错误(没有这样的文件或目录),这是完全不可能的:) – NDM

+0

我已经为文件添加了一个额外的检查,所以你不想打开一个目录。 – NDM

0

PHP设置中的“allow_url_fopen”标志是否相应地设置?

- >PHP filesystem configuration

或者,也许别的东西阻止通过HTTP访问文件PHP?

+0

请不要使用它,这是一个安全风险。 http://stackoverflow.com/questions/127534/should-i-allow-allow-url-fopen-in-php – NDM