文件没有移动到提到的directry

时间:2017-01-11 20:32:06

标签: php

在下面的代码中插入数据到db工作但移动上传的文件不起作用

请告诉我在下面的代码中我做错了

插入代码

<?php
include('dbconnection.php');
if(isset($_POST['Submit']))
  {  
      $mid=$_POST['mid'];
      $language=isset($_POST['language']) ? $_POST['language'] : "";      
      $songname=$_POST['songname'];
      $melody=$_POST['Melody'];
      $singername1=$_POST['singer'];
      $singername2=$_POST['singer1'];
      $rating=$_POST['rating'];

    function GetImageExtension($imagetype)
     {
       if(empty($imagetype)) return false;
       switch($imagetype)
       {
           case 'image/bmp': return '.bmp';
           case 'image/gif': return '.gif';
           case 'image/jpeg': return '.jpg';
           case 'image/png': return '.png';
           default: return false;
       }
     }   
if (!empty($_FILES["uploadedsong"]["name"])) {

    $file_name=$_FILES["uploadedsong"]["name"];
    $temp_name=$_FILES["uploadedsong"]["tmp_name"];
    $imgtype=$_FILES["uploadedsong"]["type"];
    $imagename=$songname;

    $target_path = "songs/$songname.jpg";


    $query_upload="INSERT into songs (mid,language,song_name,Melody,singer_name1,singer_name2,songpath,rating) VALUES ('".$mid."','".$language."','".$songname."','".$melody."','".$singername1."','".$singername2."','".$target_path."','".$rating."')";
    if($db->query($query_upload)) 
    { 
        move_uploaded_file( $temp_name,  $target_path); //this is not working
        echo("<script language='javascript'>window.alert('Song Added Successfull..!') </script>");
        echo "<script>location.href='admin_songs.php'</script>";    
    }
    else
    {
       exit("Error While uploading on the server");
    } 
    }
}

?>

我的表格

<form action="admin_song_insert.php" enctype="multipart/form-data" method="post">
   <div class="form-group">
     <label for="Movie Id">Movie Id:</label>
    <input type="Movie Id" class="form-control" id="mid" name="mid" value="<?php echo $Mid?>">
   </div>
   <div class="form-group">
     <label for="Catagory">Language:</label>
     <select class="form-control" id="language" name="language" >
        <option>Kannada</option>
        <option>English</option>
        <option>Hindi</option>
        <option>Telugu</option>
        <option>Tamil</option>
        <option>Malayalam</option>
    </select>
  </div>
  <div class="form-group">
    <label for="Movie Name">Song name:</label>
    <input type="Movie Name" class="form-control" id="songname" name="songname">
  </div>
  <div class="form-group">
    <label for="Catagory">Melody:</label>
    <select class="form-control" id="Melody" name="Melody" >
        <option>No</option>
        <option>Yes</option>
    </select>
  </div>
  <div class="form-group">
    <label for="Year">Singer Name(Male):</label>
    <input type="Year" class="form-control" id="singer" name="singer">
  </div>
  <div class="form-group">
    <label for="Hero Name">Singer Name(FeMale):</label>
    <input type="Hero Name" class="form-control" id="singer1" name="singer1">
  </div>
  <div class="form-group">
    <label for="Rating">Rating :</label>
    <input type="Rating" class="form-control" id="rating" name="rating">
  </div>
  <table style="border-collapse: collapse; font: 12px Tahoma;" border="1" cellspacing="5" cellpadding="5">
     <tbody>
        <tr>
            <td>
                <input name="uploadedsong" type="file" id="uploadedsong" value="Choose Song To upload">
            </td>
        </tr>
     </tbody>
 </table>
 <br>                                
<input class='styled-button-1' name="Submit" type="Submit" value="Submit">                      

请帮我解决此问题,并提前致谢

0 个答案:

没有答案