TimString Posted February 13, 2013 Share Posted February 13, 2013 I have these lines in a php script: passthru("whoami"); $tims_path = "localhost/DispatchReports/DispatchReportsFolder"; if ( !file_exists($tims_path) ) { mkdir ($tims_path, 0777); } if (is_dir($tims_path)) { die( "timstring, you cannot use fopen on a directory path." ); } //if the path is a directory and you want to put a new file there, you'll need to first check if it is writable: if (!is_writable($tims_path)) { die("timstring, " . $tims_path . " is not writable so you will not be able to write anything to it"); } $FileName = $tims_path . $System . ' ' . $EndMO . '.csv'; $fh = fopen($FileName, "w"); No matter how I write tims_path, mkdir won't create the folder. if I create the folder in finder, if (!is_writable($tims_path)) returns that the folder is not writeable. I have tried many many many combinations of permissions on the target folder and nothing has worked. HELP!! tim Link to comment https://forums.phpfreaks.com/topic/274460-cannot-write-to-directory/ Share on other sites More sharing options...
Jessica Posted February 13, 2013 Share Posted February 13, 2013 Does the DispatchReports folder exist already? Link to comment https://forums.phpfreaks.com/topic/274460-cannot-write-to-directory/#findComment-1412333 Share on other sites More sharing options...
jazzman1 Posted February 13, 2013 Share Posted February 13, 2013 Where is located "localhost/DispatchReports/DispatchReportsFolder" on the root web server directory or somewhere else on the system? Link to comment https://forums.phpfreaks.com/topic/274460-cannot-write-to-directory/#findComment-1412339 Share on other sites More sharing options...
TimString Posted February 15, 2013 Author Share Posted February 15, 2013 Quote Does the DispatchReports folder exist already? I have tried both ways. The first thing in the routine is if the folder doesn't exist, create it. The mkdir command does not do anything. If I create the folder in Finder, I get the same results. Quote Where is located "localhost/DispatchReports/DispatchReportsFolder" on the root web server directory or somewhere else on the system? Yes, localhost is usually the root web server Link to comment https://forums.phpfreaks.com/topic/274460-cannot-write-to-directory/#findComment-1412703 Share on other sites More sharing options...
Jessica Posted February 15, 2013 Share Posted February 15, 2013 You don't normally use localhost as a folder name though. It's the host, like a domain name sort of. You would just use DispatchReports. Link to comment https://forums.phpfreaks.com/topic/274460-cannot-write-to-directory/#findComment-1412706 Share on other sites More sharing options...
TimString Posted February 15, 2013 Author Share Posted February 15, 2013 localhost/ is the equivalent to www.whereshallwego.org/ and is a valid starting point. With that said, I have tried all sorts of path designations including '/DispatchReportFolder/' and '/DispatchReports/DispatchReportFolder/ but none work. Link to comment https://forums.phpfreaks.com/topic/274460-cannot-write-to-directory/#findComment-1412710 Share on other sites More sharing options...
jazzman1 Posted February 15, 2013 Share Posted February 15, 2013 Short description: Quote Default name describing the local computer address also known as the loopback address. For example, typing: ping localhost would ping the local IP address of 127.0.0.1 (the loopback address). When setting up a web server or software on a web server, 127.0.0.1 is used to point the software to the local machine. To find the real path to web root directory, you could use the php realpath() function. Put this line of code to the DispatchReports and find absolute path: <?php echo 'The absolute path to this directory is <b>'.realpath(".").'</b>'; Link to comment https://forums.phpfreaks.com/topic/274460-cannot-write-to-directory/#findComment-1412711 Share on other sites More sharing options...
TimString Posted February 16, 2013 Author Share Posted February 16, 2013 The absolute path to this directory is /Library/WebServer/Documents/DispatchReports. In other words, localhost/dispatchreports. How does this exercise help me? Link to comment https://forums.phpfreaks.com/topic/274460-cannot-write-to-directory/#findComment-1412738 Share on other sites More sharing options...
jazzman1 Posted February 16, 2013 Share Posted February 16, 2013 Well, I suppose that you are using an apple machine so I do not have any experience with it but.....try this: Create a new file called it - mkdir.php and place it , let's say into DispatchReports directory (it does not matter where is it b/s we are using an absolute path) The script below has to create a new directory, named - DispachReportFolder. Try, passthru("whoami"); $tims_path = "/Library/WebServer/Documents/DispatchReports/DispachReportFolder"; if ( !file_exists($tims_path) ) { mkdir ($tims_path, 0777); } if (is_dir($tims_path)) { die( "timstring, you cannot use fopen on a directory path." ); } //if the path is a directory and you want to put a new file there, you'll need to first check if it is writable: if (!is_writable($tims_path)) { die("timstring, " . $tims_path . " is not writable so you will not be able to write anything to it"); } $FileName = $tims_path . $System . ' ' . $EndMO . '.csv'; $fh = fopen($FileName, "w"); Link to comment https://forums.phpfreaks.com/topic/274460-cannot-write-to-directory/#findComment-1412776 Share on other sites More sharing options...
Jessica Posted February 16, 2013 Share Posted February 16, 2013 Localhost is not A Folder on your machine. Link to comment https://forums.phpfreaks.com/topic/274460-cannot-write-to-directory/#findComment-1412782 Share on other sites More sharing options...
jazzman1 Posted February 16, 2013 Share Posted February 16, 2013 On 2/16/2013 at 2:02 PM, Jessica said: Localhost is not A Folder on your machine. Well, it could be if he tries to create a virtual host using the apache server configuration - http://httpd.apache....s/examples.html But, in this particular example, I'm agree with you - localhost is not a real directory, it's a loopback address. Link to comment https://forums.phpfreaks.com/topic/274460-cannot-write-to-directory/#findComment-1412784 Share on other sites More sharing options...
TimString Posted February 16, 2013 Author Share Posted February 16, 2013 On 2/16/2013 at 2:02 PM, Jessica said: Localhost is not A Folder on your machine. No, I never said that localhost was a folder. localhost is the root directory of my website, the same as 127.0.0.1. Every URL I have ever seen starts with the root directory. i.e. www.micro$oft.com, www.apple.com. If you were to go to my website across the wide expanse of the web, you'd get www.thissiteislocked.com/index.html which is nothing more than two links leading to two different folders. Or, you'd get the same results with 74.??.###.95. In other words, you'd end up with www.thissiteislocked.com/dispatchreports/index.php . Since the index.php or index.html files are at the root level of the web address and are what the web is looking for one or the other when a site is browsed, they can be left out. The folder I'm trying to write to is www.thissiteislocked.com/dispatchreports/dispatchreportsfolder/ . Since I am not going across the internet to get to my site, the URL I have to use is localhost/dispatchreports. Quote $tims_path ="/Library/WebServer/Documents/DispatchReports/DispachReportFolder"; I tried that earlier per your suggestion and it didn't work then. I also tried "Library:WebServer:Documents:DispatchReports:DispatchReportsfolder:", which is the pathname that Mac and unix boxes use, with the same results. The problem is not in the path itself. I have tried several path names, and I am told that I don't have write permissions to my folder. I have had a trap that looks to see if the last folder exists, and now, the directory folder already exists and the trap is not triggered. I have no idea why the php script will write to 'localhost/dispatchreports', and not to 'localhost/dispatchreports/dispatchreportsfolder' when both have identical permissions. I have even tried the evil "everyone read/write". From what research I have done lately, the problem lies in Apache. I have tried several "solutions" and none work. I was hoping that someone here has had the same problem. Link to comment https://forums.phpfreaks.com/topic/274460-cannot-write-to-directory/#findComment-1412835 Share on other sites More sharing options...
Jessica Posted February 16, 2013 Share Posted February 16, 2013 When you're creating folders and files you don't use the domain name, you use the path from the root. I've never seen someone try to create a folder by using the full domain name. Which is what you're doing. Link to comment https://forums.phpfreaks.com/topic/274460-cannot-write-to-directory/#findComment-1412837 Share on other sites More sharing options...
jazzman1 Posted February 16, 2013 Share Posted February 16, 2013 Well, "dispatchreports" is not the same to "DispatchReports". Can you explain as this ? Link to comment https://forums.phpfreaks.com/topic/274460-cannot-write-to-directory/#findComment-1412838 Share on other sites More sharing options...
jazzman1 Posted February 16, 2013 Share Posted February 16, 2013 Quote I have no idea why the php script will write to 'localhost/dispatchreports', and not to 'localhost/dispatchreports/dispatchreportsfolder' when both have identical permissions. If that one is true, open the apple terminal and give it a full permission as root to an "dispatchreportsfolder" using a chmod unix command with recursive in the end. Example: [jazzman@localhost ~]$ chmod 777 /Library/WebServer/Documents/dispatchreports/dispatchreportsfolder -R Link to comment https://forums.phpfreaks.com/topic/274460-cannot-write-to-directory/#findComment-1412841 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.