Re: [PHP] cannot figure out permissions for fopen/fwrite
Mari Masuda wrote: Yes, currently the tmp folder (or any folders in my Apache htdocs folder) is not accessible to the web due to the Mac's built-in firewall set to block all incoming traffic except network time and something installed by Adobe when I installed CS4 (e.g., Photoshop, InDesign, etc.). However, I was wondering what the normal technique is for writing files if the script that does the fopen/fwrite is located on a production server that IS on the web. It occurred to me that I could create a 777 folder outside of the web root so that it would not be accessible on the web even if the script was running on a production server, but I wasn't sure if that was a good or bad idea. On Jul 2, 2009, at 17:59, Waynn Lue wrote: The tmp folder isn't accessible from the web though, right? Someone would first have to get access to your server for that. On 7/1/09, Mari Masuda mbmas...@stanford.edu wrote: On Jul 1, 2009, at 12:54, Shawn McKenzie wrote: Mari Masuda wrote: On Jul 1, 2009, at 12:20, Shawn McKenzie wrote: Shawn McKenzie wrote: Mari Masuda wrote: Hello, This is probably a dumb newbie question. I am running PHP 5.2.5 and Apache 2.2.8 on my Mac Book Pro OS X 10.4.11. I compiled PHP and Apache from source a while ago (as opposed to using the built-in web server that is included w/ Mac OS X). I have written the below PHP whose purpose is to read an existing comma separated (CSV) file and save the data into a text file that I can later copy and paste from into my website content management system. The problem is that on my Mac, I cannot seem to figure out what permissions I need to set in order to make the input CSV and the initially non-existant output text file readable and writable by Apache/PHP. I have Googled and come across many pages about different ways to set permissions and different permissions to set but none of the ways suggested that I tried seemed to work for me. As a temporary solution, I uploaded my PHP file to a Windows 2003 server running Apache and PHP and it worked flawlessly (and makes me suspicious that there is some huge security hole with the Windows box since it was able to execute with no permissions modifications). Any tips would be greatly appreciated. Thanks! Mari --- start my code --- ?php $in = fopen(/Applications/apache/htdocs/wp-php/wp.csv, r); $out = fopen(/Applications/apache/htdocs/wp-php/tableToCutAndPaste.txt, w); $counter = 0; fwrite($out, table\n); while(($data = fgetcsv($in)) !== FALSE) { $paperNumber = $data[0]; $authors = $data[1]; $title = $data[2]; $filename = $paperNumber . .pdf; if(($counter % 2) == 0) { fwrite($out, tr\n); } else { fwrite($out, tr style=\background: #cc;\\n); } fwrite($out, tda href=\http://www.example.com/workingpapers/getWorkingPaper.php? filename=$filename\$paperNumber/a/td\n); fwrite($out, td$authors/td\n); fwrite($out, td$title/td\n); fwrite($out, /tr\n); $counter++; } fwrite($out, /table\n); fclose($in); fclose($out); ? --- end my code --- What are the permissions on /Applications/apache/htdocs/wp-php/ ? Apache needs write permissions on that dir in order to create the file tableToCutAndPaste.txt. It's probably not a secure idea to give write permissions to that dir, so maybe create a subdir of tmp and change those permissions (one way): mkdir /Applications/apache/htdocs/wp-php/tmp chmod a+w /Applications/apache/htdocs/wp-php/tmp Also, turn on error reporting so that you can see the exact problem. It may not be what you think. -- Thanks! -Shawn http://www.spidean.com Thanks for the suggestions. I added the following lines to the very top of my code: error_reporting(E_ALL); mkdir(/Applications/apache/htdocs/wp-php/tmp, 0777, true); chmod(/Applications/apache/htdocs/wp-php/tmp, a+w); and I also changed the line where it tries to open the file to write to to go to the new directory: $out = fopen(/Applications/apache/htdocs/wp-php/tmp/ tableToCutAndPaste.txt, w); Below are the errors I got: --- start errors --- Warning: mkdir() [function.mkdir]: Permission denied in /Applications/apache/htdocs/wp-php/generateTable.php on line 5 Warning: chmod() [function.chmod]: No such file or directory in /Applications/apache/htdocs/wp-php/generateTable.php on line 6 Warning: fopen(/Applications/apache/htdocs/wp-php/tmp/tableToCutAndPaste.txt) [function.fopen]: failed to open stream: No such file or directory in /Applications/apache/htdocs/wp-php/generateTable.php on line 9 Warning: fwrite(): supplied argument is not a valid stream resource in /Applications/apache/htdocs/wp-php/generateTable.php on line 13 Warning: fwrite(): supplied argument is not a valid stream resource in
Re: [PHP] cannot figure out permissions for fopen/fwrite
The tmp folder isn't accessible from the web though, right? Someone would first have to get access to your server for that. On 7/1/09, Mari Masuda mbmas...@stanford.edu wrote: On Jul 1, 2009, at 12:54, Shawn McKenzie wrote: Mari Masuda wrote: On Jul 1, 2009, at 12:20, Shawn McKenzie wrote: Shawn McKenzie wrote: Mari Masuda wrote: Hello, This is probably a dumb newbie question. I am running PHP 5.2.5 and Apache 2.2.8 on my Mac Book Pro OS X 10.4.11. I compiled PHP and Apache from source a while ago (as opposed to using the built-in web server that is included w/ Mac OS X). I have written the below PHP whose purpose is to read an existing comma separated (CSV) file and save the data into a text file that I can later copy and paste from into my website content management system. The problem is that on my Mac, I cannot seem to figure out what permissions I need to set in order to make the input CSV and the initially non-existant output text file readable and writable by Apache/PHP. I have Googled and come across many pages about different ways to set permissions and different permissions to set but none of the ways suggested that I tried seemed to work for me. As a temporary solution, I uploaded my PHP file to a Windows 2003 server running Apache and PHP and it worked flawlessly (and makes me suspicious that there is some huge security hole with the Windows box since it was able to execute with no permissions modifications). Any tips would be greatly appreciated. Thanks! Mari --- start my code --- ?php $in = fopen(/Applications/apache/htdocs/wp-php/wp.csv, r); $out = fopen(/Applications/apache/htdocs/wp-php/tableToCutAndPaste.txt, w); $counter = 0; fwrite($out, table\n); while(($data = fgetcsv($in)) !== FALSE) { $paperNumber = $data[0]; $authors = $data[1]; $title = $data[2]; $filename = $paperNumber . .pdf; if(($counter % 2) == 0) { fwrite($out, tr\n); } else { fwrite($out, tr style=\background: #cc;\\n); } fwrite($out, tda href=\http://www.example.com/workingpapers/getWorkingPaper.php? filename=$filename\$paperNumber/a/td\n); fwrite($out, td$authors/td\n); fwrite($out, td$title/td\n); fwrite($out, /tr\n); $counter++; } fwrite($out, /table\n); fclose($in); fclose($out); ? --- end my code --- What are the permissions on /Applications/apache/htdocs/wp-php/ ? Apache needs write permissions on that dir in order to create the file tableToCutAndPaste.txt. It's probably not a secure idea to give write permissions to that dir, so maybe create a subdir of tmp and change those permissions (one way): mkdir /Applications/apache/htdocs/wp-php/tmp chmod a+w /Applications/apache/htdocs/wp-php/tmp Also, turn on error reporting so that you can see the exact problem. It may not be what you think. -- Thanks! -Shawn http://www.spidean.com Thanks for the suggestions. I added the following lines to the very top of my code: error_reporting(E_ALL); mkdir(/Applications/apache/htdocs/wp-php/tmp, 0777, true); chmod(/Applications/apache/htdocs/wp-php/tmp, a+w); and I also changed the line where it tries to open the file to write to to go to the new directory: $out = fopen(/Applications/apache/htdocs/wp-php/tmp/ tableToCutAndPaste.txt, w); Below are the errors I got: --- start errors --- Warning: mkdir() [function.mkdir]: Permission denied in /Applications/apache/htdocs/wp-php/generateTable.php on line 5 Warning: chmod() [function.chmod]: No such file or directory in /Applications/apache/htdocs/wp-php/generateTable.php on line 6 Warning: fopen(/Applications/apache/htdocs/wp-php/tmp/tableToCutAndPaste.txt) [function.fopen]: failed to open stream: No such file or directory in /Applications/apache/htdocs/wp-php/generateTable.php on line 9 Warning: fwrite(): supplied argument is not a valid stream resource in /Applications/apache/htdocs/wp-php/generateTable.php on line 13 Warning: fwrite(): supplied argument is not a valid stream resource in /Applications/apache/htdocs/wp-php/generateTable.php on line 22 Warning: fwrite(): supplied argument is not a valid stream resource in /Applications/apache/htdocs/wp-php/generateTable.php on line 27 Warning: fwrite(): supplied argument is not a valid stream resource in /Applications/apache/htdocs/wp-php/generateTable.php on line 28 Warning: fwrite(): supplied argument is not a valid stream resource in /Applications/apache/htdocs/wp-php/generateTable.php on line 29 Warning: fwrite(): supplied argument is not a valid stream resource in /Applications/apache/htdocs/wp-php/generateTable.php on line 30 Warning: fwrite(): supplied argument is not a valid stream resource in /Applications/apache/htdocs/wp-php/generateTable.php on line 35 Warning: fclose():
Re: [PHP] cannot figure out permissions for fopen/fwrite
Yes, currently the tmp folder (or any folders in my Apache htdocs folder) is not accessible to the web due to the Mac's built-in firewall set to block all incoming traffic except network time and something installed by Adobe when I installed CS4 (e.g., Photoshop, InDesign, etc.). However, I was wondering what the normal technique is for writing files if the script that does the fopen/fwrite is located on a production server that IS on the web. It occurred to me that I could create a 777 folder outside of the web root so that it would not be accessible on the web even if the script was running on a production server, but I wasn't sure if that was a good or bad idea. On Jul 2, 2009, at 17:59, Waynn Lue wrote: The tmp folder isn't accessible from the web though, right? Someone would first have to get access to your server for that. On 7/1/09, Mari Masuda mbmas...@stanford.edu wrote: On Jul 1, 2009, at 12:54, Shawn McKenzie wrote: Mari Masuda wrote: On Jul 1, 2009, at 12:20, Shawn McKenzie wrote: Shawn McKenzie wrote: Mari Masuda wrote: Hello, This is probably a dumb newbie question. I am running PHP 5.2.5 and Apache 2.2.8 on my Mac Book Pro OS X 10.4.11. I compiled PHP and Apache from source a while ago (as opposed to using the built-in web server that is included w/ Mac OS X). I have written the below PHP whose purpose is to read an existing comma separated (CSV) file and save the data into a text file that I can later copy and paste from into my website content management system. The problem is that on my Mac, I cannot seem to figure out what permissions I need to set in order to make the input CSV and the initially non-existant output text file readable and writable by Apache/PHP. I have Googled and come across many pages about different ways to set permissions and different permissions to set but none of the ways suggested that I tried seemed to work for me. As a temporary solution, I uploaded my PHP file to a Windows 2003 server running Apache and PHP and it worked flawlessly (and makes me suspicious that there is some huge security hole with the Windows box since it was able to execute with no permissions modifications). Any tips would be greatly appreciated. Thanks! Mari --- start my code --- ?php $in = fopen(/Applications/apache/htdocs/wp-php/wp.csv, r); $out = fopen(/Applications/apache/htdocs/wp-php/ tableToCutAndPaste.txt, w); $counter = 0; fwrite($out, table\n); while(($data = fgetcsv($in)) !== FALSE) { $paperNumber = $data[0]; $authors = $data[1]; $title = $data[2]; $filename = $paperNumber . .pdf; if(($counter % 2) == 0) { fwrite($out, tr\n); } else { fwrite($out, tr style=\background: #cc;\ \n); } fwrite($out, tda href=\http://www.example.com/workingpapers/getWorkingPaper.php? filename=$filename\$paperNumber/a/td\n); fwrite($out, td$authors/td\n); fwrite($out, td$title/td\n); fwrite($out, /tr\n); $counter++; } fwrite($out, /table\n); fclose($in); fclose($out); ? --- end my code --- What are the permissions on /Applications/apache/htdocs/wp-php/ ? Apache needs write permissions on that dir in order to create the file tableToCutAndPaste.txt. It's probably not a secure idea to give write permissions to that dir, so maybe create a subdir of tmp and change those permissions (one way): mkdir /Applications/apache/htdocs/wp-php/tmp chmod a+w /Applications/apache/htdocs/wp-php/tmp Also, turn on error reporting so that you can see the exact problem. It may not be what you think. -- Thanks! -Shawn http://www.spidean.com Thanks for the suggestions. I added the following lines to the very top of my code: error_reporting(E_ALL); mkdir(/Applications/apache/htdocs/wp-php/tmp, 0777, true); chmod(/Applications/apache/htdocs/wp-php/tmp, a+w); and I also changed the line where it tries to open the file to write to to go to the new directory: $out = fopen(/Applications/apache/htdocs/wp-php/tmp/ tableToCutAndPaste.txt, w); Below are the errors I got: --- start errors --- Warning: mkdir() [function.mkdir]: Permission denied in /Applications/apache/htdocs/wp-php/generateTable.php on line 5 Warning: chmod() [function.chmod]: No such file or directory in /Applications/apache/htdocs/wp-php/generateTable.php on line 6 Warning: fopen(/Applications/apache/htdocs/wp-php/tmp/ tableToCutAndPaste.txt) [function.fopen]: failed to open stream: No such file or directory in /Applications/apache/htdocs/wp-php/generateTable.php on line 9 Warning: fwrite(): supplied argument is not a valid stream resource in /Applications/apache/htdocs/wp-php/generateTable.php on line 13 Warning: fwrite(): supplied argument is not a valid stream resource in /Applications/apache/htdocs/wp-php/generateTable.php on line 22 Warning: fwrite(): supplied argument is not a