Menu

Save plot to output file

gt651
2012-01-07
2012-09-07
  • gt651

    gt651 - 2012-01-07

    In this function: $plot->SetOutputFile($output_file)

    How do I use http://my_server/graph.jpg for
    $output_file?

     
  • lbayuk

    lbayuk - 2012-01-07

    If your application is running on "my_server", just provide the full pathname
    (not a URL). For example, if the web server root is /var/www then the path
    would be "/var/www/graph.jpg". Of course, the web server process needs to have
    create or write permissions to create or overwrite the file. (Which is usually
    not a good idea.)

    If you are asking about saving a plot to a different (remote) server, I don't
    think you can do it like that. First, because you cannot store files over HTTP
    URLs (you can read, not write). You would have to use something like an FTP.
    Also I don't know if the GD extension to PHP supports remote files. It might
    depend on how PHP and the GD extension were built.

     
  • gt651

    gt651 - 2012-01-07

    Yes I just want to save it to the same directory on the same server. I guess
    my question is this?

    $plot->SetOutputFile(graph.jpg);

    $plot->SetOutputFile('graph.jpg');

    $plot->SetOutputFile("graph.jpg");

    Which of these do I use?

    When I get this working I want to run it as a cron job once an hour so it will
    need to overwrite the old image.

     
  • lbayuk

    lbayuk - 2012-01-07

    Either the 2nd or 3rd. The 1st is not valid because the filename needs to be
    quoted.

    Remember PHPlot makes you use $plot->SetIsInline(TRUE) - else it will ignore
    SetOutputFile.

    I recommend using a path with that filename, though. If you are going to run
    your PHP script via cron using the command-line version (CLI) of PHP, the
    working directory does not change to where the script is located. If you try
    this via cron without a path on the output file, it is likely to either fail
    because of file permissions, or else the file will end up in an unexpected
    directory.

     
  • gt651

    gt651 - 2012-01-07

    OK here's what I have but it still doesn't work but the screen version
    (commented out) works.

     
  • lbayuk

    lbayuk - 2012-01-07

    What does it do, or not do?

    You know you still have to call $plot->DrawGraph() for file output, right?
    PHPlot doesn't really do anything at all until DrawGraph() - everything else
    is just setup, stores things into the object. That includes SetOutputFile() -
    it just remembers the filename you want to write to.

     
  • gt651

    gt651 - 2012-01-07

    No I didn't know I needed all 3 lines - thanks it works now.

    Now on to getting it to run as a cron job.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.