I've set file permissions to 777 yet I am unable to email the file with PHP.

I'm able to clearly see during my FTP client the file has 0777 permissions so when I actually do:

echo (true === is_writable('file.txt')) ? 'yes' : 'no';

I recieve 'no'

I additionally attempted:

echo (true === chmod('file.txt', 0777)) ? 'yes' : 'no';

With similar result.

Your directory listing goes something similar to this:

    public          0777
        css         0755
        js          0755
        file.txt    0777

And I am using .htaccess file to redirect all visitors to the general public subfolder. Obviously, I've excluded the file from spinning (it's accessible in the browser I checked):

RewriteRule  ^(file).*  - [L]

Can you explain that?

I suppose Apache runs like a different user/group compared to user/group possessing the file. By which situation, the file itself must be 0777.

public only must be 0777 should you intend on adding files towards the folder using PHP. Even when the folder is not 0777, when the file is and also the folder has a minimum of 5 for that user (read/execute), you need to have the ability to email the file.

Ultimately, your file tree need to look such as this:

        file.txt  0777

Naturally, you will not have the ability to change individuals permissions using PHP, but that can be done out of your FTP client.

Whether it still is not working, PHP may be running in safe mode or you will be utilising extra time for example PHP Suhosin. You can find better result altering who owns the file towards the same user/group that's running the script.

To obtain the user/group id from the performing user, you can utilize the next:

echo getmyuid().':'.getmygid(); //ex:. 0:0

Then, you can utilize chown (within the terminal) to alter who owns the file:

> chown 0:0 file.txt

Any chance the folder the file is within isn't writable through the webserver?

You need to chmod the file immediately after you create it.

function Doo_Chmod($path, $chmod = null)
    if (file_exists($path) === true)
    	if (is_null($chmod) === true)
    		$chmod = (is_file($path) === true) ? 644 : 755;

    		if (in_array(get_current_user(), array('apache', 'httpd', 'nobody', 'system', 'webdaemon', 'www', 'www-data')) === true)
    			$chmod += 22;

    	return chmod($path, octdec(intval($chmod)));

    return false;

No offense, but is the road to 'file.txt' correct ? (I am talking about, are you currently testing the right file)