ok i see...
If, the folder is under .htaccess protection of Apache server, then do below:
well you can use the header() to send appropriate headers to the browser.
once again check the manual, php.net?header
e.g.
header('Location: http://blah.com');
above will actually send the user to above URL, as the header is sent to the browser. Similarly, there is paramter to send auth headers to the browser, using:
header('Authenticate: blah');
(the above syntax may not be correct, please check the manual)
If the protected folder is outside the server root, and you dont have the 'unix user rights' to the folder to write to it, then you need to give your PHP module the rights to write to that specific folder. Then you can write files in there. else make the folder to chmod 777 ... 🙂