我正在尝试将文件名插入“音频”表中的“音频文件”列。问题是它一直给我一个未定义的索引错误:tmp_name 第 45 行。这意味着当我尝试插入文件名时,而不是执行以下操作:
声音的
AudioId (auto) AudioFile
1 AudioFiles/cat.png
2 AudioFiles/cat_2.png
3 AudioFiles/cat_3.png
它在下面这样做:
声音的
AudioId (auto) AudioFile
1 AudioFiles/_2.png
2 AudioFiles/_2.png
3 AudioFiles/_2.png
所以我的问题是为什么它找不到 tmp 名称并因此在表中插入不正确的文件名:
$result = 0;
if( file_exists("AudioFiles/".$_FILES['fileAudio']['name'])) {
$parts = explode(".",$_FILES['fileAudio']['name']);
$ext = array_pop($parts);
$base = implode(".",$parts);
$n = 2;
while( file_exists("AudioFiles/".$base."_".$n.".".$ext)) $n++;
$_FILES['fileAudio']['name'] = $base."_".$n.".".$ext;
move_uploaded_file($_FILES["fileAudio"]["tmp_name"], //line 45 notice appears
"AudioFiles/" . $_FILES["fileAudio"]["name"]);
$result = 1;
}
else
{
move_uploaded_file($_FILES["fileAudio"]["tmp_name"],
"AudioFiles/" . $_FILES["fileAudio"]["name"]);
$result = 1;
}
$audiosql = "INSERT INTO Audio (AudioFile)
VALUES (?)";
if (!$insert = $mysqli->prepare($audiosql)) {
// Handle errors with prepare operation here
}
//Dont pass data directly to bind_param store it in a variable
$insert->bind_param("s",$aud);
//Assign the variable
$aud = 'AudioFiles/'.$_FILES['fileAudio']['name'];
$insert->execute();
if ($insert->errno) {
// Handle query error here
}
$insert->close();
下面是表格:
var $fileAudio = $("<form action='audioupload.php' method='post' enctype='multipart/form-data' target='upload_target_audio' onsubmit='return audioClickHandler(this);' class='audiouploadform' >" +
"<p class='audiof1_upload_process' align='center'>Loading...<br/><img src='Images/loader.gif' /><br/></p>" +
"<p class='audiof1_upload_form' align='center'><br/><span class='audiomsg'></span><label>" +
"Audio File: <input name='fileAudio' type='file' class='fileAudio' /></label><br/><br/><label class='audiolbl'>" +
"<input type='submit' name='submitAudioBtn' class='sbtnaudio' value='Upload' /></label>" +
"<iframe class='upload_target_audio' name='upload_target_audio' src='#' style='width:300px;height:300px;border:0px;solid;#fff;'></iframe></form>");