1 回答

TA貢獻1862條經(jīng)驗 獲得超6個贊
我已經(jīng)閱讀了所有我能在 stackoverflow 上找到的關(guān)于這個問題的信息!這可能是重復(fù)的,但我無法解決我的問題: 我無法使用 php 處理文件。
我已經(jīng)使用這些命令獲得許可:
sudo chown -R www-data:www-data /var/www/mysite
sudo chmod -R 777 /var/www/mysite
這是代碼:
<?php
if(isset( $_POST['save_values'])) { // retrieve the form data by using the element's name attributes value as key
if(!empty($_POST['getURL'])) {
$URL = $_POST['getURL'];
}
if(!empty($_POST['getRefreshRate'])) {
$RefreshRate = $_POST['getRefreshRate'];
}
if(!empty($_POST['getBrightness'])) {
$Brightness = $_POST['getBrightness'];
}
}
$filename = "/currentSettings.txt";
chmod($filename,0777);
$cSettings = fopen($filename, "r");
if($cSettings) {
echo "$cSettings exists";
while(($line = fgets($cSettings)) !== false) {
$arr = explode("\n", $line);
$URL = $arr[0];
$RefreshRate = $arr[1];
$Brightness = $arr[2];
}
fclose($cSettings);
} else {
echo "File does not exist";
fclose($cSettings);
$cSettings = fopen('/currentSettings.txt', 'w');
fwrite($cSettings,$URL."\n");
fwrite($cSettings,$RefreshRate."\n");
fwrite($cSettings,$Brightness."\n");
fclose($cSettings);
}
?>
它總是返回File does not exist。它不會寫入文件,也不會從文件中讀取。我什至在 www/mysite 中手動創(chuàng)建了該文件,但它仍然無法讀取。
我對 PHP 很陌生,我確信我的代碼壞了,但我找不到修復(fù)它的方法。
- 1 回答
- 0 關(guān)注
- 160 瀏覽
添加回答
舉報