开发者

enable temporary file creation and usage in Apache/PHP by Python/R/any external program - best options

I have a python/R script, that uses both Python and R to compute a figure. The actual figure is generated by R and it can be stored as a PNG image. This works fine when tested on the machine, in a folder with correct permissions, but I have to do it online now. I have an Apache/PHP interface that sends the user data to the Python script, and the Python script works with R to compute the figure.

At this moment the picture cannot be stored on Apache by R. What is the best way to enable this temporary file creation by external programs like R and Python? Further on, I need the picture to be displayed, then deleted at the end of the PHP session.

While certainly useful, any methods that only allow access for Python, or R are not good enough. My question is one of client-server 'modus operandi' in Apache: suppose program X is called by PHP. How is it best to allow program X to store and send pictures/text/whatever to PHP and how to implement that?

Creating a se开发者_StackOverflow中文版rver-accessible folder with full permissions seems like a security black hole.


With R, you can tempfile generates filenames for temp files. You could also use file.remove to delete the file later, but it sounds like this would be done best from PHP code (if it to be removed when the PHP session finishes).

plot_file <- paste(tempfile(tmpdir = "some_dir_with_write_permission"), "png", sep = ".")

png(plot_file)
plot(1:10)
dev.off()

#later on ...
file.remove(plot_file)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜