Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

GD::Graph problem help much appreciated

by LinuxNoobPhilip (Novice)
on Jan 25, 2008 at 23:14 UTC ( [id://664392]=perlquestion: print w/replies, xml ) Need Help??

LinuxNoobPhilip has asked for the wisdom of the Perl Monks concerning the following question:

I hope this is a good place to Post this. I am using GD:graph to make so nice pretty graphs to put on a little web page I am making, I am trying to make it somewhat dynamic, user chooses which graph they would like, Perl script called from which the graph is generated. Problem: all works out great until I try to Open the file where I will save the graph. I do the following. open(IMG, ">../images/the_image.$format") or die "Can't write file: $!"; and here is the error I receive Can't write file: Permission denied at /var/www/cgi-bin/getgraph.pl I don't know if you guys could tell me how to fix this. I am sure its simple I am quite a noob, still in college
  • Comment on GD::Graph problem help much appreciated

Replies are listed 'Best First'.
Re: GD::Graph problem help much appreciated
by thezip (Vicar) on Jan 25, 2008 at 23:23 UTC

    You'll need to specify that physical path as it relates to the file system, rather than the webserver's concept of document_root.

    Try specifying an explicit path as a destination to prove this, "/tmp/foo.$format" for example.


    Your wish is my commandline.
Re: GD::Graph problem help much appreciated
by Errto (Vicar) on Jan 25, 2008 at 23:23 UTC

    Well, first of all you've done the first step which is checking the actual error that your code is throwing, so that puts you a bit ahead of the game.

    A permission denied probably error means one of two things:

    • you don't have write access to the directory you're trying to write to
    • you're trying to access the wrong directory
    The first one could be the case if your CGI program is running as a different user than you're expecting. You can check this by printing out the user ID (though don't do this in production code!). The second one could be the case if the current directory is not where you expect it to be. Specifically, just because your code is in /var/www/cgi-bin does not necessarily mean that /var/www/cgi-bin is the current directory when your code runs. You can work around this by hard-coding the absolute path of the directory or fetching it from some kind of configuration variable.

Re: GD::Graph problem help much appreciated
by LinuxNoobPhilip (Novice) on Jan 25, 2008 at 23:40 UTC
    /tmp/foo

    worked just great.

    I guess there are some followup questions.

    1. what user does the browser use? is it the one I log into at terminal with?

    2. what would be a good folder to put the images in?

    it appears no where in the /var/www area may I do this in ....

      1.I think you mean "What user does the server use?". Assuming that it is apache then ps -ef | grep http will show you the owner of the process.

      2. You will need to ask your system administrator but a directory somewhere under your home directory is probably a safe bet. You will need to ensure that the web server can write there by changing the group and giving group write permission.

        Well This is my set-up on my local machine, I guess I need to know how to change the group permissions then. Write now I can only get files in my www directory a subdirectories to work in the browser.

        What you are saying is there is a way to tell apache it can look in a directory back and pull from a folder there? if so what would be the step.

Re: GD::Graph problem help much appreciated
by LinuxNoobPhilip (Novice) on Jan 26, 2008 at 00:34 UTC
    http://www.usenet-forums.com/apache-web-server/11734-allowing-cgi-script-create-write-directory.html

    this link looks like what i am trying to do. What is the best way to get my CGI-Script to write to a file/folder which one of my web pages in my /var/www directory can access. (I am running apache2)
Re: GD::Graph problem help much appreciated
by LinuxNoobPhilip (Novice) on Jan 25, 2008 at 23:44 UTC
    The site will not load the picture located in /temp directory, it seems :(

Re: GD::Graph problem help much appreciated
by leighsharpe (Monk) on Jan 26, 2008 at 12:34 UTC
    You need to create the image files in a directory that is in your web site's document root. Your last comment indicates that it is probably in /var/www. Therefore, if you create a folder in /var/www, and call it, say, 'graph_files', then you want to write your image files to /var/www/graph_files, and then when you send your web page to the browser, the image tag should be <img src="graph_files/<filename>">

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://664392]
Approved by Errto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-19 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found