Pregunta

I have a PHP script that loads content of a 175KB file but fails at the very top of the page. (It works with smaller file as it should be!!) Here's the script snippet:

        if(!file_exists($sFile) || !is_readable($sFile)) {
            echo "<span style='color: #FF3333;'>Can not find/open file.</span><br />";
        } else {
            if(isset($_GET['content']) && is_writable($sFile)) {
                $hFile = fopen($sFile, "w");
                fwrite($hFile, urldecode($_GET['content']));
                fclose($hFile);
            }

            $sContent = file_get_contents($sFile);
        }
        ?>
        <a href="<?php echo "?page=browser&path=" . dirname(realpath($sFile)); ?>" title="Back to <?php echo dirname(realpath($sFile)); ?>">
            &raquo; Back to <i><?php echo dirname(realpath($sFile)); ?></i>
        </a>

        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
            <input type="hidden" name="page" value="edit" />
            <input type="hidden" name="file" value="<?php echo $sFile; ?>" />
            <textarea name="content" placeholder="..." style="margin: 0; padding: 0; width: 100%; height: 350px; resize: vertical;"><?php echo $sContent; ?></textarea>
            <input type="submit" value="Save changes" style="width: 100%;" />
        </form>
¿Fue útil?

Solución

Judging by the title of your question, I'd say PHP's set_time_limit would be your solution. However, after reading your question entirely, it also could be a memory limit set in place inside of php.ini or a hard limit that the server has.

You could try using fopen() and fread() instead, such as:

$f = fopen("yourfile.txt", "r");
$s = "";
while (!feof($f)) {
  $s .= fread($f, 4096);
}
fclose($f);
// do something with the file contents inside of $s

You could also expand upon this example so that it echoes out the file as it reads it in.

Hope that helps.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top