简体   繁体   English

我收到未定义的索引tmp_name通知

[英]I am getting an undefined index tmp_name notice

I am trying to insert the name of the file into the "AudioFile" column in the "Audio" Table. 我正在尝试将文件名插入“音频”表的“音频文件”列中。 Problem is that it keeps giving me an undefined index error: tmp_name line 45. This means when I try to insert the name of a file, instead of doing the below: 问题是它一直给我一个未定义的索引错误:tmp_name第45行。这意味着当我尝试插入文件名时,而不是执行以下操作:

Audio 音讯

AudioId (auto)  AudioFile
1               AudioFiles/cat.png
2               AudioFiles/cat_2.png
3               AudioFiles/cat_3.png

It is doing this below: 它在下面执行此操作:

Audio 音讯

AudioId (auto)  AudioFile
1               AudioFiles/_2.png
2               AudioFiles/_2.png
3               AudioFiles/_2.png

So my question is why can't it find the tmp name and hence inserts incorrect file name in the table: 所以我的问题是为什么它找不到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();

Below is the form: 形式如下:

 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>"); 

IT's quite hard to quess which line is 45, but rule of thumb here is that if it says that index in undefined then it really is. IT部门很难确定哪一行是45行,但是这里的经验法则是,如果说未定义的索引确实是45行。 There are two common reasons: you made typo in index name trying to read it, or it simply is not there. 有两个常见的原因:您试图在索引名称中输入拼写错误以尝试读取它,或者它根本不存在。 You can easily check what indexes are present by printing array content out with print_r() or even var_dump() . 您可以通过使用print_r()甚至var_dump()输出数组内容来轻松检查存在哪些索引。 Then you either fix your typo or try to find why it is not here (if it really should be unconditionally). 然后,您要么修正拼写错误,要么尝试找出为什么不在这里(如果确实是无条件的话)。 I'd also check your <FORM> and see if your <input type="file"... /> element is really named and its name is "fileAudio". 我还要检查您的<FORM> ,看看您的<input type="file"... />元素是否真正命名,其名称为“ fileAudio”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM