多上传php脚本并存储在mysql数据库中 [英] Muliple upload php script and store in mysql database

查看:96
本文介绍了多上传php脚本并存储在mysql数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的.

我需要将多个mp3文件上传到一个目录,并将它们存储在mysql的音频"表中.

I need to upload Multiple mp3 files to a directory and store them in the 'audio' table in mysql.

我正在使用此脚本,但是它仅适用于一个文件,每次都只做一次跟踪很烦人.这就是为什么我需要多个上传脚本.

I'm using this script but it works only with one file, it's annoying to do one track each time. That's why I need a multiple upload script.

我只想这样写每个曲目的标题:

I wish to only write the title of each track like this:

php: file1.mp3 [0] file2.mp3 [1] file3.mp3 [2]

html form: File 1 title: .... File 2 title: .... File 3 title: ....

insert to 'audio' 

对不起,我的英语不好.我希望你知道我的意思

Sorry for my bad English. i hope you know what I mean

<?php if(isset($_POST['kkupload'])){ 
    $filename = $_FILES['foto']['name'];
    $extensie = substr($filename, -3);

    $map = "/mounted-storage/home150/sub007/sc80538-VHHY//audio/files/";
    $file = $_FILES['foto'];

    $breedte = $_FILES['foto'];
    $max_bytes = 100000000000;


    if(strtolower($extensie) != "mp3" && strtolower($extensie) != "jpg" && strtolower($extensie) != "jpeg" && strtolower($extensie) != "png" && strtolower($extensie) != "bmp")
    {
        echo "Je kan alleen .gif, .jpg .jpeg en .png bestanden uploaden!";
    }

    elseif($_FILES['foto']['size'] > $max_bytes) { echo("Het bestand is groter dan ".$max_bytes." bytes!"); }

    else {

    $length = strlen($filename);
    $name = "pict";
    $name = substr($filename, 0, $length - 4);
    $i = "1";
    $tempname = $name;

    $picName = $_FILES['foto']['name'];
    $titel      = htmlspecialchars($_POST['titel']);
    $bericht    = $_POST['bericht'];
    $url        = htmlspecialchars($_POST['pica']);
    $youtube    = $_POST['youtube'];
    $nr = rand(0,99999999999);
    if(file_exists($_FILES['foto']['name']))
    {
        $picName = $nr. $_FILES['foto']['name'];
        if(file_exists($picName))
        {
            $picName = $nr. $_FILES['foto']['name'];
        }       
    }

    move_uploaded_file($_FILES['foto']['tmp_name'], $map.$_FILES['foto']['name']."") or die("Fout met uploaden plaatje");
    mysql_query("INSERT INTO `audio` (titel, url, categorie) values ('".$titel."', '/audio/files/".$picName."','".$bericht."')");
    echo "je hebt succesvol nieuws geupload!";      }}?>

<form action="?pagina=addnieuws" method="post" enctype="multipart/form-data" name="form1" id="form1">
            <table width="100%" border="0" cellpadding="2" cellspacing="2" id="form1">
              <tr>
                <td width="77"><b> <font size="2" face="Verdana">Tite track:</font></b>
                    </div></td>
                <td><font size="2">
                  <input name="titel" type="text" id="Titel" size="63" />
                </font></td>
              </tr>
              <tr>
                <td width="77"><b> <font size="2" face="Verdana">Plaatje:</font></b>
                    </div></td>
                <td><font size="2">
                  <input type="file" name="foto" size="52" />
                  </font><b><font size="1" face="Verdana"> <br />
                    MP3</font></b></td>
              </tr>
              <tr>
                <td valign="top" width="77"><b> <font size="2" face="Verdana">Artiest:</font></b>
                  </div></td>
                <td>
  <script type="text/javascript">
bkLib.onDomLoaded(function() {
new nicEditor({fullPanel : true}).panelInstance('area2'); 
});
</script>
  <select name="bericht">
              <?php
$query = mysql_query("SELECT * FROM artiesten ORDER BY naam ASC");
while ($array = mysql_fetch_assoc($query)){
	echo "<option value=\"". $array['naam'] ."\">". $array['naam']. "</option>";
}
?>
            </select>
  </td>
              </tr>
              <tr>
                <td width="77" colspan="2"><font size="2">
                  <input type="submit" name="kkupload" value="Upload" />
                </font></td>
              </tr>
            </table>
          </form>

推荐答案

下面的代码是一个示例,使您可以了解如何一次将一个以上的文件上传到一个文件夹中

The code below is a example to give you a idea of how to upload more then one file at a time but to a folder

for($i=0; $i < count($_FILES['filesToUpload']['name']); $i++){
$target_dir = "../uploads/";
$target_file = $target_dir . basename($_FILES['filesToUpload']['name'][$i]);
$uploadOk = 1;

在上面和下面的代码之间插入安全检查代码,以查看文件是否确实是mp3等.

Insert your security check code here between the above and below code to see if the file really is a mp3 and etc.

if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded. ";
} else {
if (move_uploaded_file($_FILES["filesToUpload"]["tmp_name"][$i], $target_file)) {
        echo "The file ". basename( $_FILES["filesToUpload"]["name"][$i]). " has been uploaded. ";
    } else {
        echo "Sorry, there was an error uploading your file. ";
    }
}
}

另外,根据所用数据库的类型,可能最好将文件保存在文件夹中,而不是直接保存在数据库内部,以免造成数据库过大..相反,您需要保存它到数据库的文件路径,然后从该文件路径打开.但这只是给您一个建议.

Also, depending on the type of database you're using, probably best to save the files in a folder and not directly inside the database so that you're not over-bloating the database.. You instead would need to save its file path to the database and then open from the file path. Though that's just giving you a suggestion.

最后,那只是PHP的一面,不确定SQL部分需要什么.虽然我猜很好,因为您主要询问如何进行多个文件上传.

Lastly, that's just the PHP side of it, not sure what you'll need for the SQL part. Though I guess that's fine since you mainly asked for how to do multiple file uploads.

这篇关于多上传php脚本并存储在mysql数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆