0

I am using XAMPP(PHP APACHE MYSQL) to develop a program in MAC. When I try to use JPGRAPH to write to file, code: $fileName = "/img/bar.png"; $graph->img->Stream($fileName); I got this warning: Cant write to file, check that the process running PHP has enough permission. I searched a lot, and tried many ways: 1.sudo chmod 777 ~/File/Java/img 2.change user name in Apache httpd.conf (default username is nobody) 3.mkdir($create_path, 0777). Still I cant figure it out. Any suggestion?

Li'
  • 3,133
  • 10
  • 34
  • 51

2 Answers2

2

Try removing the / at the start of /img/bar.png

James McDonnell
  • 3,600
  • 1
  • 20
  • 26
  • Agreed. You are attempting to write relative to the root of the boot disk, not relative to your application. – Joshua Kaiser Nov 21 '12 at 05:48
  • Yep, you could also just prepend a . to your path like so ./img/bar.png – James McDonnell Nov 21 '12 at 05:55
  • Just tried removing the /, but still got the same warning msg. – Li' Nov 21 '12 at 05:58
  • could you post your file hierarchy starting at the root of your application, and tell us which file this code is in? – James McDonnell Nov 21 '12 at 06:00
  • the code is in the file named barshow.php, path: ~/Applications/XAMPP/xamppfiles/htdocs/Twitter/barshow.php. Twitter dir is the project dir. img dir is also in the Twitter dir: .../Twitter/img – Li' Nov 21 '12 at 06:26
0

Try

 
   $root = $_SERVER["DOCUMENT_ROOT"] . "/img";
   $fileName = "$root/bar.png";
 

Hope this helps.

Kneel-Before-ZOD
  • 4,141
  • 1
  • 24
  • 26