我是新来的。
我需要将多个mp3文件上传到目录并将它们存储在mysql的'audio'表中。
我正在使用这个脚本,但它只适用于一个文件,每次执行一个轨道很烦人。这就是我需要多个上传脚本的原因。
我希望只写下每首曲目的标题:
php: file1.mp3 [0] file2.mp3 [1] file3.mp3 [2]
html form: File 1 title: .... File 2 title: .... File 3 title: ....
insert to 'audio'
抱歉我的英语不好。我希望你知道我的意思
<?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>
答案 0 :(得分:0)
下面的代码是一个示例,可让您了解如何一次上传多个文件,但文件夹
for($i=0; $i < count($_FILES['filesToUpload']['name']); $i++){
$target_dir = "../uploads/";
$target_file = $target_dir . basename($_FILES['filesToUpload']['name'][$i]);
$uploadOk = 1;
在上面和下面的代码之间插入您的安全检查代码,以查看该文件是否真的是一个mp3等。
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. ";
}
}
}
此外,根据您使用的数据库类型,最好将文件保存在文件夹中,而不是直接保存在数据库中,这样您就不会使数据库过度膨胀。需要将其文件路径保存到数据库,然后从文件路径打开。虽然这只是给你一个建议。
最后,这只是它的PHP方面,不确定你对SQL部分需要什么。虽然我认为这很好,因为你主要询问如何进行多个文件上传。