Forgive me if I am not clear on this but here is what I am trying to accomplish. I have two php pages that each generate a separate json file when each form is submitted. What I want to do is require the main.php to be filled out before the second.php can be filled out. So, if the user goes to the second.php before they fill out the main.php it will redirect them to the main.php. So I need the second.php to "search" for the path to the main.json file and, if empty, redirects back to the main.php. Here is a portion of the code that generates the main.json. The json files are saved on my website.
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;
}
}