1
原諒我,如果我不清楚這一點,但這是我正在嘗試完成。我有兩個php頁面,每個頁面在每個表單提交時生成一個單獨的json文件。我想要做的是在第二個.php可以填寫之前填寫main.php。因此,如果用戶在填寫main.php之前轉到second.php,它會將它們重定向到main.php。所以我需要second.php來搜索main.json文件的路徑,如果爲空,則重定向回main.php。以下是生成main.json的代碼的一部分。 json文件保存在我的網站上。重定向到一個網頁,如果JSON爲空
require_once $this->site_path . 'inc' . DIRECTORY_SEPARATOR . 'json_file.class.php';
$jsonFile = new JsonFile();
$json_result = $jsonFile->writeFile(
array(
'file_name' => $this->site_path . DIRECTORY_SEPARATOR . 'users' . DIRECTORY_SEPARATOR . $file_data['username'] . DIRECTORY_SEPARATOR . 'main.json',//$this->json_path . DIRECTORY_SEPARATOR . $file_data['username']. '_'. 'main.json',
'data' => $obj
)
);
$result['json_file'] = $json_result;
// Save the uploaded file
if (!empty($file_data['profilebackground']['size'])) {
$target = $this->site_path . DIRECTORY_SEPARATOR . 'users' . DIRECTORY_SEPARATOR . $file_data['username']. DIRECTORY_SEPARATOR . $file_name;
if (!move_uploaded_file($file_data['profilebackground']['tmp_name'], $target)) {
$result['image_file'] = 'There was an error saving the home page image. Please check the image directory permissions and try again.';
error_log('File ' . $file_data['profilebackground']['name'] . ' not saved: check the image directory permissions.');
} else {
include_once("php_img_lib.php");
img_resize($target, $target, 1000, 1000, $ext);
$result['image_file'] = 'The home page image was successfully uploaded.';
}
} else {
// $result['image_file'] = 'There was an error uploading the home page image. Please try again.';
// error_log('File ' . $file_data['profilebackground']['name'] . ' not uploaded.');
}
return $result;
}
public function getmainData($username) {
$albums_json_file = $this->site_path . DIRECTORY_SEPARATOR . 'users' . DIRECTORY_SEPARATOR . $username . DIRECTORY_SEPARATOR . 'main.json';//$this->json_path . DIRECTORY_SEPARATOR . $username . '_'. 'main.json';
try {
$handle = @fopen($albums_json_file, "rb");
if (!empty($handle)) {
$albums_json_file_contents = fread($handle, filesize($albums_json_file));
fclose($handle);
}
if (!empty($albums_json_file_contents)) {
$albums_json_file_contents = json_decode($albums_json_file_contents);
} else {
$albums_json_file_contents = array();
}
if (!empty($albums_json_file_contents->main[0])) {
return $albums_json_file_contents->main[0];
} else {
return $albums_json_file_contents;
}
} catch (Exception $e) {
error_log($e->getMessage());
$albums_json_file_contents = array();
return $albums_json_file_contents;
}
}
是否可以檢查main.php是否被填寫?還是我沒有正確理解。你的意思是可以直接進入second.php,而不必先擊main.php? – bmcculley
您可以在設置JSON-flle – osanger
後設置會話值這兩個php文件是兩個單獨的鏈接。因此,用戶可以按下我網站上的「第二個」按鈕並轉到該頁面。他們可以轉到第二頁,而不必轉到主頁。那就是問題所在。我需要第二個頁面來獲取main.json的內容。而且,如果爲空,它將重定向到主頁面。 – iSITKiosk