请我同时上传两个文件并将信息添加到mySQL

时间:2018-05-14 00:45:23

标签: php mysql

请我同时上传两个文件并将信息添加到mySQL,我不知道我在哪里做错了。请帮帮我,下面是我的代码 `

$name = $_POST['music_name'];
$uploader = $_POST['music_uploader'];
$artist = $_POST['music_artist'];
$lyrics  = $_POST['music_lyrics'];
$file = (starz_hit_cf)."-".$_FILES['file']['name'];
$art = (art_for)."-".$_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$art_loc = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$folder="../downloads/";
$art_hold="../../assets/img/arts/";

// new file size in KB
$new_size = $file_size/1024;  
// new file size in KB

// make file name in lower case
$new_file_name = strtolower($file);
$new_art_name = strtolower($art);
// make file name in lower case

$final_file=str_replace(' ','-',$new_file_name);
$final_art=str_replace(' ','-',$new_art_name);
$date =date('Y-m-d H:i:s');

if(move_uploaded_file($file_loc,$folder.$final_file))
if(move_uploaded_file($art_loc,$art_hold.$final_art))
{
    $sql="INSERT INTO tbl_music (musicName,musicUploader,musicArtist,musicLyrics,musicfile,musicArt,musicType,musicSize,musicDate) VALUES('$name','$uploader','$lyrics','$final_file','$final_art','$file_type','$new_size','$date')";
    mysql_query($sql);
    ?>
    <script>
    alert('successfully uploaded');
    window.location.href='index?success';
    </script>
    <?php
}
else
{
    ?>
    <script>
    alert('error while uploading file');
    window.location.href='index?fail';
    </script>
    <?php
}
}
?>

感谢您的回复。

0 个答案:

没有答案