有2页,一个是主页,另一个包含在其中
主页
<?php
$var_value = 7;
$_SESSION['varname'] = $var_value;
include 'upload_image.php';
?>
和包含的页面
<?php
include 'init.php';
if (!logged_in()) {
header('Location: index.php');
exit();
}
include 'template/header.php';
?>
<h3>Upload image</h3>
<?php
if (isset($_FILES['image'], $_POST['image_n'], $_POST['image_description'])) {
$image_name = $_FILES['image']['name'];
$bytes = $_FILES['image']['size'];
$image_temp = $_FILES['image']['tmp_name'];
$image_n = $_POST['image_n'];
$image_description = $_POST['image_description'];
$allowed_ext = array('jpg', 'jpeg', 'png', 'gif', 'rar', 'pdf');
//$image_ext = strtolower(end(explode('.', $image_name)));
$image_ext = pathinfo($image_name, PATHINFO_EXTENSION);
$album_id = $_SESSION['varname'];
$errors = array();
if (empty($image_name) || empty($album_id) || empty($image_n) || empty($image_description)) {
$errors[] = 'Something is missing';
} else {
if (strlen($album_name) > 55 || strlen($album_description) > 255) {
$errors[] = 'One or more fields contains too many characters';
}
if (in_array($image_ext, $allowed_ext) === false) {
$errors[] = 'File type not allowed';
}
//if ($image_size > 2097152) {
// $errors[] = 'Maximum file size is 2mb';
//}
if (album_check($album_id) === false) {
$errors[] = 'Couldn\'t upload to that album';
}
}
if (!empty($errors)) {
foreach ($errors as $error) {
echo $error, '<br />';
}
} else {
$byte = formatSizeUnits($bytes);
upload_image($image_temp, $image_ext, $album_id, $image_n, $image_description, $byte);
header('Location: view_album.php?album_id='.$album_id);
exit();
}
}
$albums = get_albums();
if (empty($albums)) {
echo'<p>You don\'t have any albums. <a href="create_album.php">Create an album</a></p>';
} else {
?>
<form action="" method="post" enctype="multipart/form-data">
<div class="choose">
<p>Choose a file:<br /><input type="file" name="image" /></p>
</div>
<div class="des">
<p>Name*:<br /><input type="text" name="image_n" maxlength="55"/></p>
<p>Description*:<br /><textarea name="image_description" rows="6" cols="35" maxlength="255"></textarea></p>
<p><input type="submit" value="Upload" /></p>
</div>
</form>
<div class="foot">
<?php
}
include 'template/footer.php';
?>
</div>
第二页末尾的表格不加载..但是当我删除主页面的第一行$ var_value = 7;最后加载时的表单..我不知道是什么问题或者有其他方法在主要设置专辑值并将其传递给包含的页面
答案 0 :(得分:1)
如果在$album_id
中找不到问题(由$var_value
设置,则包含的文件会执行以下操作:
$byte = formatSizeUnits($bytes);
upload_image($image_temp, $image_ext, $album_id, $image_n, $image_description, $byte);
header('Location: view_album.php?album_id='.$album_id);
exit();
所以它永远不会到达显示表单的部分。
答案 1 :(得分:0)
包含第二个代码?如果是这样,你可以使用
$album_id = $var_value
而不是:
$album_id = $_SESSION['varname'];
代码的第二个代码......不需要会议。