views:

100

answers:

1

I am trying to read and post back to the browser a file uploaded with the zend framework mechanism.

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?

A: 

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__));
raspi
Thanks it is obvious that this is a permissions issue, I will try it and will inform ASAP...
dimitris mistriotis
Considered as correct, because there was as well a permissions issue.What was the real problem after that:I had forgotten to trim the result from the postgresql, having as input not only the filename but a large number of trailing spaces as well. The real-fix therefore was a trim(...) call.
dimitris mistriotis