Ajax文件上传并将详细信息和表单文件详细信息插入到Db

时间:2018-01-31 13:52:10

标签: php jquery mysql ajax

请知道我的帖子中的一些主题是在这里,但实际上似乎并没有解决我的问题。我有一个上传器类,我的Ajax上传工作正常,没有PHP连接。现在上传后我试图调用我的文件类来将详细信息存储到数据库但实际上没有工作。我在youtube上搜索了所有这些,没有人看到解决我的问题

error_reporting(0);
if (isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {


$path = "uploads/"; //set your folder path
//set the valid file extensions 
$valid_formats = array("jpg", "png", "gif", "bmp", "jpeg", "GIF", "JPG", "PNG", "doc", "mp3", "txt", "docx", "pdf", "xls", "xlsx", "mp4"); //add the formats you want to upload

$name = $_FILES['myfile']['name']; //get the name of the file

$size = $_FILES['myfile']['size']; //get the size of the file

if (strlen($name)) { //check if the file is selected or cancelled after pressing the browse button.
    list($txt, $ext) = explode(".", $name); //extract the name and extension of the file
    if (in_array($ext, $valid_formats)) { //if the file is valid go on.
        if ($size < 9433098888) { // check if the file size is more than 2 mb
            $file_name  = $_POST['filename'];
            $new = $_POST['music_new'];  //get the file name
            $tmp        = $_FILES['myfile']['tmp_name']; 

            if (move_uploaded_file($tmp, $path . $file_name.'.'.$ext)) { //

                 $sam->musicUpload('name','format','so on');

                //please am in need of this. if i type echo $file_name works but can actually insert to my db.. i have no problem with my back end

                }  

            else {
                echo "failed";
            }
        } else {
            echo "File size max 2 MB";
        }
    } else {
        echo "Invalid file format..";
    }
} else {
    echo "Please select a file..!";
}

include'../../header.php';

      echo $url;
}


<div class='category-tab shop-details-tab'><!--category-tab-->
<div class='col-sm-12'>
    <ul class='nav nav-tabs'>
        <li><a href='#details' data-toggle='tab'>Details</a></li>
        <li><a href='#companyprofile' data-toggle='tab'>Company Profile</a></li>
        <li><a href='#tag' data-toggle='tab'>Tag</a></li>
        <li class='active'><a href='#reviews' data-toggle='tab'>Reviews (5)</a></li>
    </ul>
</div>
<div class='tab-content'>
    <div class='tab-pane fade' id='details' >
        <div class='col-sm-3'>
            <div class='product-image-wrapper'>
                <div class='single-products'>
                    <div class='productinfo text-center'>
                        <img src='images/home/gallery1.jpg' alt='' />
                        <h2>$56</h2>
                        <p>Easy Polo Black Edition</p>
                        <button type='button' class='btn btn-default add-to-cart'><i class='fa fa-shopping-cart'></i>Add to cart</button>
                    </div>
                </div> 
            </div>
        </div>

    </div>

    <div class='tab-pane fade' id='companyprofile' >

        <div class='col-sm-3'>
            <div class='product-image-wrapper'>
                <div class='single-products'>
                    <div class='productinfo text-center'>
                        <img src='images/home/gallery4.jpg' alt='' />
                        <h2>$56</h2>
                        <p>Easy Polo Black Edition</p>
                        <button type='button' class='btn btn-default add-to-cart'><i class='fa fa-shopping-cart'></i>Add to cart</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class='tab-pane fade' id='tag' >

        <div class='col-sm-3'>
            <div class='product-image-wrapper'>
                <div class='single-products'>
                    <div class='productinfo text-center'>
                        <img src='images/home/gallery4.jpg' alt='' />
                        <h2>$56</h2>
                        <p>Easy Polo Black Edition</p>
                        <button type='button' class='btn btn-default add-to-cart'><i class='fa fa-shopping-cart'></i>Add to cart</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class='tab-pane fade active in' id='reviews' >
        <div class='col-sm-12'>
            <ul>
                <li><a href=''><?php if($logged){ echo $username;}else{echo'Not Logged';}?></a></li>
                <li><a href=''><i class='fa fa-clock-o'></i>12:41 PM</a></li>
                <li><a href=''><i class='fa fa-calendar-o'></i>31 DEC 2014</a></li>
            </ul>
            <p> Plese make sure to upload Relevant files or else it will be deleted by the Head  Admin(s). Thanks for Understanding</p>
            <p><b>Write Your Review</b></p>


        <div class="row">

    <div class='tab-pane fade active in' id='reviews' >
        <div class='col-sm-12'>
            <h3>jQuery Ajax file upload with percentage progress bar</h3>
            <form id="myform" method="post">

                <div class="form-group">
                    <label>Enter the file name: </label>
                    <input class="form-control" type="text" id="filename" /> 
                </div>
             <span>
                    <input type="text" placeholder="Database Name"  id='music_name'/>
                    <input type="text" placeholder="Producer"" id="music_producer" />
                </span>
                <br>

                <span>
                    <input type="text" placeholder="Artist Name"  id="music_artist"/>
                    <input type="text" placeholder="Album Name"/>
                </span><br>
                  <textarea name="" placeholder="Music Description" id='music_desc'></textarea>
                <div class="form-group">
                    <label>Select file: </label>
                    <input class="form-control" type="file" id="myfile" />
                </div>
                <div class="form-group">
                    <div class="progress">
                        <div class="progress-bar progress-bar-success myprogress" role="progressbar" style="width:0%">0%</div>
                    </div>

                    <div class="msg"></div>
                </div>

                <input type="button" id="btn" class="btn-success" value="Upload" />
            </form>

             <?php   include'generalModal.php';
             ?>
        </div>
    </div>
</div> 
        </div>
    </div>

</div>
</div><!--/category-tab-->  






<?php

include_once'../../music/reCommend.php'; echo'
<script src="'.$url.'panel/uploadMusic/processUpload.js"></script>'; 

include '../../Blog/Footer.php';

0 个答案:

没有答案