views:

24

answers:

1

Through the imap_* functions of php i'm trying to store the attachments of the emails on my server. I want to store the contents ($c, string) of the file with filename($f) in a sub-directory named with a thread id ($thread). m_attpath is a defined constant pointing absolute to the base folder.

    if(!is_dir(m_attpath.$thread)){
         mkdir(m_attpath.$thread);
    };

$handle = fopen(m_attpath.$thread.'/'.$f, 'w+');
fwrite($handle, $c);
fclose($handle);

But now i'm struggeling with the permissions i need to set in order to let the attachements viewable through an download.php page.

the main folder m_attpath = 0777 the thread folder is 0644 the files them self are also 0644

When viewing the files through my browser they end up as an question mark. The browser doesn;t display an 404 warning. In an ftp programm i can see the size of the attachments. Something is wrong, but i cant find what. Can anyone help me with this?

thanx

A: 

if m_attpath is a constant this code is wrong.

Should be

$handle = fopen(m_attpath.$thread.'/'.$f, 'w+');

What do you mean with "they end up as a question mark"?

Raoul Duke
that $ is a typo."They end up as a question mark": The browser displays a question mark instead of the picture itself. So it doesn't gets a 404 but it looks like it's not readable.
richardverbruggen
what happens if you open the files directly (not through the browser)? I take it the file size looks ok because you mentioned that you can see it in a ftp program. Seems to me that it's not a permission problem because the permissions look ok and if it were you would get either a php warning writing the file or a 403 when accessing them through the browser. Frankly I'm at a loss. Could you post more code? I suggest to verify that $c really contains what you expect. It shouldn't make any difference on a linux system but you should use "wb+" for binary files btw.
Raoul Duke