执行外部命令后PHP返回空白页

时间:2015-01-04 01:35:54

标签: php linux shell

我的剧本:

<?php
include 'theme.php';
/*ceklogin();*/
css();
if($_POST['wget-send'])
    {
        $formdir=$_POST['dir'];
        $formlink=$_POST['link'];
        $toSave = nl2br($_POST["link"]);
        $simpan = str_replace('<br />', '', $toSave);
    $filelink = fopen('/root/wget/wget-download-link.txt',a);
    $filedir = fopen('/root/wget/wget-dir.txt',w);

    fwrite($filedir, $formdir);
    fwrite($filelink, $simpan. "\n");
    }

if($_POST['restart-download'])
    {
    exec('mv /root/wget/wget-download-link.txt.done /root/wget/wget-download-link.txt > /dev/null 2>&1 &');
    exit();
    }

if($_POST['stop-wget'])
    {
    exec('killall wget > /dev/null 2>&1 &');
    exit();
    }

echo "<form action=\"".$PHP_SELF."\" method=\"post\" id=\"WgetForm\">";
echo "Download directory:<br><input type=\"text\" name=\"dir\" size=\"15\" value=\"/mnt/usb/\"/><br>";
echo '<br>Download link:';
echo ("<textarea name=\"link\" rows=\"13\" cols=\"62\"></textarea><br>");
echo '
<input type="submit" onclick="DownloadRestarted()" name="restart-download" value="Restart latest download" id="RestartWget" />
<input type="submit" onclick="LinkAdded()" name="wget-send" value="Download" id="WgetID" />
<input type="submit" onclick="WgetStopped()" name="stop-wget" value="Stop Wget" id="StopWget" />
</form>
</div>';
echo <<<HTML
<script type="text/javascript">

function LinkAdded()
    {
            alert("Link has been sucessfully sent to wget, it'll be downloaded soon, check the wget log for the download progress");
    }
function DownloadRestarted()
    {
            alert("Download restarted, check the wget log for the download progress");
    }
function WgetStopped()
    {
            alert("Wget has been successfully stopped, no download is running right now");
    }

</script>
HTML;
foot();
echo '
</div>
</body>
</div>
</html>';
?>

请注意exec部分。每当我点击Restart latest downloadStop Wget时,它总会返回一个空白页面。我的剧本出了什么问题?解决它的唯一临时方法是摆脱exec部分,但它也会让我无法使这些按钮工作。

1 个答案:

答案 0 :(得分:0)

exit()块中删除if,这就是您的网页空白的原因

exit()终止当前脚本