simple PHP filesystem path problem

I have been writing to a file in the same directory as the script with no problems. Then when it came to writing to a file in the subdirectory it failed. the code I used is here..

      $destinationfile = "./".$teacherid."/template.csv";
      echo $destinationfile;      

      $handle = fopen($destinationfile,"w+");

      echo $handle;

                      etc. etc....



echoing $destination file gives...       ./1/template.csv

and echoning the $handle gives nothing in the subdirectory case and a resource with number when working in the same directory..

I have also tried the path written as              /1/template.csv               but no luck either

Any tips anyone? Thanks
ARC_UMAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

WarpsehCommented:
Have you tried without the ./ before your path? Also, i think that if it is a windows platform you should use the windows format ("path\\file")
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Beverley PortlockCommented:
Try this

      $dirName = dirname( $_SERVER['PHP_SELF'] );

      $destinationfile = "$dirName/".$teacherid."/template.csv";
      echo $destinationfile;      

      $handle = fopen($destinationfile,"w+");

      echo $handle;

There may be an extra '/' in there - I can't recall if dirname() leaves a trailing slash
0
ARC_UMAuthor Commented:
i thought that was going to fix it for sure..
now im fopening

/onlinealps/1/template.csv

but still no handle.. can anyone see what else is wrong?
0
Beverley PortlockCommented:
What is the full path name to the file in question?

Also try this

      $destinationfile = realpath( './1/template.csv' );

      echo $destinationfile;      

      $handle = fopen($destinationfile,"w+");

      echo $handle;
0
Beverley PortlockCommented:
One other thought that occurs - check permissions on both the file and the directory. If you are on Linux then PHP runs under Apache and uses the Linux username of wwwrun or www-data depending on the distro. Check these users have access to both the file and the directory.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.