开发者

zend framework: can not access file that is already there

I am trying to read and post back to the browser a file uploaded with the zend framework me开发者_如何学Gochanism.

The file has been uploaded correctly to the desired location and as I have checked by

su www-data 

and after an ls and a cat, the web user can read it and modify it properly.

the problem is that inside a controller when I try to:

if(!file_exists($fileName)) {
die("File ($fileName) wasnt set or it didnt exist");
}

I am always getting to die(...), although the $fileName is a string and when I display it's location I can always (as stated before) read it from the command line.

ls output:

$ ls -lah
total 112K
drwxr-xr-x 2 www-data www-data 4.0K 2009-10-07 18:21 .
drwxr-xr-x 3 www-data www-data 4.0K 2009-10-07 13:57 ..
-rw-r--r-- 1 www-data www-data  70K 2009-10-07 17:33 Eclipse_Icon_by_TZR_observer.png
-rw-r--r-- 1 www-data www-data  27K 2009-10-07 18:24 eclipse_logo2.png

Stat output:

stat() [function.stat]: stat failed for .../eclipse_logo2.png

I saw a very similar question to the "try for 30 days" site, so it is not something that has happened to me...

Any ideas?


You have to chmod the newly created file because the file owner created from PHP side will be Apache (group: www-data, httpd, www, or something similar). So next time PHP cannot access the file because www-data owns it and it has wrong permissions.

Here's how you create new files so that you can access them later.
<?php
$path = '/path/to/new/file';
touch($path)
chmod($path, 0777);
// TRY to change group, this usually fails
@chgrp($path, filegroup(__FILE__)); 
// TRY to change owner, this usually fails
@chown($path, fileowner(__FILE__));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜