简体   繁体   中英

Input type text is not receiving in php file on submit

I want to send title of the image on submit of form but its not receiving in upload.php i don't know the reason only undefined variable warning is displayed. help anybody.

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/>';
            }

    }
}
?>

error/warning:

( ! ) Notice: Undefined index: title in C:\wamp\www\multiple_image_upload\upload.php on line 5

Two reason for this

1)you forget input type for title in your form

<input type="text" name="title" />

2)May be instead of $_POST['title'] it is

 $_POST['tender']

in your upload.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM