0

I want to load a php file that located in my server to a table .

PostgreSQL version: 9.5 and User: Postgres

i tried pg_read_file() but it shows me this error :

Query failed: ERROR: absolute path not allowed in

my code:

select pg_read_file($$/home/user/web/a.php$$, 0, 200);

from this question: using pg_read_file read file in desktop PostgreSQL i got my path via :

SHOW  data_directory;

but the file is in different directory , so its useless .

i also tried copy function:

COPY cmd_exec FROM PROGRAM $$cat /home/user/web/a.php$$;SELECT query_to_xml($$SELECT * FROM cmd_exec;$$,true,true,$$$$);--+

but it shows me this error:

Warning: pg_query (): Query failed: ERROR: extra data after last expected column CONTEXT: COPY cmd_exec, line 3: "switch ($ _SESSION ['LANG_ID']) {" in /home/user/.

due to the fact that i dont know the structure of the file is its useless using this function and also it a php file not a CSV

as a final try i used lo_import(),lo_get() functions but as a result they gave me a binary result that couldn't retrieve it to a string format .

code:

SELECT (lo_import($$/home/user/a.php$$)); // will give me a oid etc:123
SELECT lo_get(123);

result: \x3c3f7068700d0a66756e6374696f6e206563686f..

i couldn't convert it to a string, is there any way to load php file to a table and print it in the page ?

Leearn2303
  • 69
  • 5

0 Answers0