Jump to content

Cannot write to directory


TimString

Recommended Posts

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
Share on other sites

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.

 

 

 

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

Edited by TimString
Link to comment
Share on other sites

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.

Edited by TimString
Link to comment
Share on other sites

Short description:

 

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>';

Edited by jazzman1
Link to comment
Share on other sites

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");

Edited by jazzman1
Link to comment
Share on other sites

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.

 

 

$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
Share on other sites

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

Edited by jazzman1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.