有人可以告诉我为什么它没有被通过。除了select选项值之外,所有其他值都被传递。这些文件完全按照我的要求获得更新。但是专辑ID并没有像我想要的那样被分配:(。
页面上的HTML代码:
<form action="" method="post" enctype="multipart/form-data" >
<label>Select Image:</label>
<input type="file" aria-required="true" size="30" id="file" name="files[]" multiple="multiple" />
<?php if(isset($_GET['al'])){ ?>
<label>Album(required):</label>
<select name='album' id='album' aria-required="true">
<?php
$query_album = "SELECT * FROM `albums` ORDER BY `id` DESC ";
$result_m = $conn->query($query_album);
if ($result_m->num_rows > 0) {
// output data of each row
while($item_a = $result_m->fetch_assoc()) {
$value= $item_a['id'];?>
<option value='<?php echo $value; ?>'>
<?php echo $item_a['title']; ?>
</option>
<?php
}
} ?>
</select>
<?php } ?>
<label>Image Title :</label>
<input type="text" aria-required="true" size="30" value="" name='title' id='title'>
<label> Image Description :</label>
<input type="text" aria-required="true" size="30" value="" name='desc' id='desc'>
<button type="submit" value="Upload!" class="soc-icon soc-icon-small soc-icon-alt fa fa-floppy-o">
</button>
<button type="reset" name="reset" class="soc-icon soc-icon-small soc-icon-alt fa fa-refresh">
</button>
<input type="hidden" name="album" id="album" value="<?php echo $album; ?>">
<a href="gallery.php" class="soc-icon soc-icon-small soc-icon-alt fa fa-arrow-left"></a>
</form>
来自UPLOAD PAGE的PHP代码,其值传递给...除了相册ID之外,所有其他值都被传递。有人可以帮我弄清楚我做错了什么。
<?php
include 'DBConfig.php';
require 'imageconfig.php';
require 'img_functions.php';
if(isset($_FILES['files'])){
if(!empty($_POST['album'])){
$album_id = $_POST['album'];
$image_title=$_POST['title'];
$image_desc=$_POST['desc'];
$errors= array();
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
$file_name = $key.$_FILES['files']['name'][$key];
$file_size =$_FILES['files']['size'][$key];
$file_tmp =$_FILES['files']['tmp_name'][$key];
$file_type=$_FILES['files']['type'][$key];
if($file_size > 2097152){
$errors[]='File size must be less than 2 MB';
}
$query="INSERT into images(`ID`,`ALBUM_ID`,`CAPTION`,`FILE_NAME`,`FILE_SIZE`,`FILE_TYPE`,`DESC`) VALUES(DEFAULT,'{$album_id}','$image_title','$file_name','$file_size','$file_type','$image_desc'); ";
$desired_dir="uploads/fullsized/";
if(empty($errors)==true){
if(is_dir($desired_dir)==false){
mkdir("$desired_dir", 0700); // Create directory if it does not exist
}
if(is_dir("$desired_dir/".$file_name)==false){
move_uploaded_file($file_tmp,"uploads/fullsized/".$file_name);
create_square_image("uploads/fullsized/".$file_name,"uploads/thumbs/".$file_name,200);
}
else{ //rename the file if another one exist
$new_dir="uploads/fullsized/".$file_name.time();
rename($file_tmp,$new_dir) ;
}
$result = mysqli_query($conn, $query);
}else{
print_r($errors);
}
}
if(empty($error)){
header('Location:gallery.php');
}
}
else {
echo"album id not set";
}
} ?>
答案 0 :(得分:2)
您正在用另一个具有相同名称的输入覆盖您的输入:
<select name='album' id='album' aria-required="true">
...
<input type="hidden" name="album" id="album" value="<?php echo $album; ?>">