php-stream-wrappers

How to restrict file system access in PHP?

こ雲淡風輕ζ 提交于 2020-12-26 09:42:17
问题 Someone knows a trick to have a PHP script self-restrict access to the file system ( fopen , file_get_contents etc.)? Such calls should be blocked except for a handful of selected file names (log file, access to /tmp and similar). This is not a security thing , but rather a means of forcing the development team not to access the file system directly (and detect spots in existing code, where this is already the case). We want to see an exception in that case (which gets caught and reported),

How to restrict file system access in PHP?

对着背影说爱祢 提交于 2020-12-26 09:41:11
问题 Someone knows a trick to have a PHP script self-restrict access to the file system ( fopen , file_get_contents etc.)? Such calls should be blocked except for a handful of selected file names (log file, access to /tmp and similar). This is not a security thing , but rather a means of forcing the development team not to access the file system directly (and detect spots in existing code, where this is already the case). We want to see an exception in that case (which gets caught and reported),

PHP: Writing a MYSQL query to CSV

我与影子孤独终老i 提交于 2020-01-02 06:18:10
问题 I'm attempting to write a MySQLi query to a downloadable CSV. The following headers open a stream for the CSV: $fileName = ''; //empty file name, file name is cast later header("Cache=Control: must-revalidate, post-check=0, pre-check=0"); header('Content-Description: File Transfer'); header("Content-type: text/csv"); header("Content-Disposition: attachment; filename={$fileName}"); header("Expires: 0"); header("Pragma: public"); $fh = @fopen( 'php://output', 'w' ); Below this I have the

php stream_get_contents hangs at the end of the stream

时间秒杀一切 提交于 2019-12-19 17:39:41
问题 Solution at the end of the question I am writing a PHP application that sends a message to a server and then reads a response back in using stream_get_contents . I communicate with the same server in an android app in the same way. The android app works fine and responds quickly, however the PHP hangs when reading the response back from the server. In the code sample below, I have set a tiny buffer size of 5 bytes to test a theory. If I remove this buffer size it hangs, however with the 5

php://input can only be read once in PHP 5.6.16

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 03:40:02
问题 PHP manual states that a stream opened with php://input support seek operation and can be read multiple times as of PHP 5.6, but I can't make it work. The following example clearly shows it doesn't work: <!DOCTYPE html> <html> <body> <form method="post"> <input type="hidden" name="test_name" value="test_value"> <input type="submit"> </form> <?php if ($_SERVER['REQUEST_METHOD'] === 'POST') { $input = fopen('php://input', 'r'); echo 'First attempt: ' . fread($input, 1024) . '<br>'; if (fseek(