0

Hi,

I am making a script that takes the file contents of another chosen file on the same server, everything in the file is pulled into a textarea including the PHP in the file. I want to know how to then save all this data to a PHP file (temporary) as a preview for the user, and if they're happy, they can then click save which will write all code to the original file which the code was pulled from.

Thank you,

Daniel

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by diafol
1

You can write it out using any of the File functions (e.g. file_put_contents) under a a temp name ending with a .php suffix. You should probably be putting it in a separate folder just for that purpose. You can give the user a link to that temp program file. If this is software that the user will load onto his/her own site and this function is well protected, then there may not be a security issue (at least not for you). If it is on your own site, then you need to carefully consider the security hole that you are opening.

Votes + Comments
Needed to be said
0

> If it is on your own site, then you need to carefully consider the security hole that you are opening.

Well said.

0

Thank you for your replies. I will consider security as I will be releasing this script free of charge, and the file put contents writes the php code as php code?

Meaning will it actually function as php or will it just show on the page it is written to?

Thanks again!

0

file_get_contents: on your own site, I think you might get the code, on another remote site, you'll get the output. file_put_contents? I think you need to create a stream_context_create(). But, I've never tried that. If you own the site, you can use ftp functions.

Edited by diafol: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.