我想在提交表单时发送图像的标题但是它没有在upload.php中接收我不知道原因只显示未定义的变量警告。帮助任何人。
multiupload.php
<!DOCTYPE html>
<html>
<head>
<title>Upload Multiple Images Using jquery and PHP</title>
<!-------Including jQuery from google------>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="script.js"></script>
<!-------Including CSS File------>
<link rel="stylesheet" type="text/css" href="style.css">
<body>
<div id="maindiv">
<div id="formdiv">
<h2>Multiple Image Upload Form</h2>
<form enctype="multipart/form-data" action="" method="post">
First Field is Compulsory. Only JPEG,PNG,JPG Type Image Uploaded. Image Size Should Be Less Than 100KB.
<hr/>
<input type="text" name="title" />
<div id="filediv"><input name="file[]" type="file" id="file"/></div><br/>
<input type="button" id="add_more" class="upload" value="Add More Files"/>
<input type="submit" value="Upload File" name="submit" id="upload" class="upload"/>
</form>
<br/>
<br/>
<!-------Including PHP Script here------>
<?php include "upload.php"; ?>
</div>
<!-- Right side div -->
<div id="formget"><a href=http://www.formget.com/app><img src="formget.jpg" alt="Online Form Builder"/></a>
</div>
</div>
</body>
</html>
upload.php的
<?php
if (isset($_POST['submit'])) {
echo 'hell';
$j = 0; //Variable for indexing uploaded image
$value = isset($_POST['title']) ? $_POST['title'] : '';
echo 'title:'.$value;
$target_path = "uploads/"; //Declaring Path for uploaded images
for ($i = 0; $i < count($_FILES['file']['name']); $i++) {//loop to get individual element from the array
$ext = explode('.', basename($_FILES['file']['name'][$i]));//explode file name from dot(.)
$file_extension = end($ext); //store extensions in the variable
if( move_uploaded_file($_FILES["file"]["tmp_name"][$i], $target_path . $_FILES["file"]["name"][$i])){
echo ($i+1).')'. $_FILES["file"]["name"][$i]. '.<span id="noerror">is uploaded successfully!.</span><br/><br/>';
} else {//if file was not moved.
echo $i. ').<span id="error">please try again!.</span><br/><br/>';
}
}
}
?>
错误/警告:
( ! ) Notice: Undefined index: title in C:\wamp\www\multiple_image_upload\upload.php on line 5
答案 0 :(得分:0)
这个的两个原因
1)您忘记了表单中title
的输入类型
<input type="text" name="title" />
2)可能不是$_POST['title']
而是
$_POST['tender']
你的upload.php中的