2016-07-11 88 views
0

我想隱藏我的彈出窗口,當我試圖上傳非圖像file.but我點擊上傳照片按鈕在彈出框中顯示一個加載符號和執行停止在該statement.here是我code.in控制檯我得到一個錯誤popup_upload不defined.please給我針對此問題的解決方案......感謝所有提前document.getElementById(「popup_upload」)。style.display ='none not working

 function addAvathar() { 

    $imgtype=$_FILES['userfile']['name']; 
    $imext=explode('.',$imgtype); 
    $ext=end($imext); 
    if(($ext!='gif')&&($ext!='jpeg')&&($ext!='png')&&($ext!='jpg')) 
    { 

     echo '<script type="text/javascript">document.getElementById("popup_upload").style.display = "none";alert("upload correct file type");</script>'; 

      exit(); 
    } 
    else{ 
    $config['upload_path'] = './avatar/'; 
    $config['allowed_types'] = 'gif|jpeg|png|jpg'; 
    $config['max_size'] = '1024mb'; 
    $config['max_width'] = '3000'; 
    $config['max_height'] = '3000'; 
    $this->load->library('upload', $config); 

    if (!$this->upload->do_upload()) { 

     $ve['data'] = $this->upload->display_errors(); 
    } else { 
     $this->upload->data(); 
    } 


    if ($this->input->post("submit")) { 
     $title = $this->input->post('title'); 

     $fInfo = $this->upload->data(); 

     if ($fInfo['image_width'] > 600) { 
      $src = './avatar/' . $fInfo['file_name']; 
      $percent = 0.5; 
      $width = $fInfo['image_width']; 
      $height = $fInfo['image_height']; 
      $newwidth = $width * $percent; 
      $newheight = $height * $percent; 

      // Load 
      $thumb = ImageCreateTrueColor($newwidth, $newheight); 
      $extention = $fInfo['file_ext']; 

      // create new jpeg image based on the target sizes 

      switch ($extention) { 
       case 'jpg': 
        $img_r = imagecreatefromjpeg($src); 
        break; 
       case 'jpeg': 
        $img_r = imagecreatefromjpeg($src); 
        break; 
       case 'png': 
        $img_r = imagecreatefrompng($src); 
        break; 
       case 'gif': 
        $img_r = imagecreatefromgif($src); 
        break; 
       default: 
        $img_r = imagecreatefromjpeg($src); 
      } 

      // Resize 
      imagecopyresized($thumb, $img_r, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); 

      imagejpeg($thumb, $src, 90); 
     } 

     $ban = array('id' => '', 'title' => $title); 
     $this->db->insert('bannar', $ban); 
     echo '<script type="text/javascript">window.top.window.show_popup_crop("../../avatar/' . $fInfo['file_name'] . '")</script>'; 
    } else { 
     $this->load->view('crop', array('edt' => $edit['result'], 'result' => $data['result'])); 
    } 
    } 
} 
+0

如果您需要Javascript幫助,請向我們展示生成的HTML文件(來自瀏覽器中的View/Source),而不是PHP腳本。這樣,我們所有了解Javascript的人,卻不知道如何在頭腦中運行PHP,可以看到瀏覽器中實際執行的是什麼。 – jfriend00

回答

0

在PHP腳本如果您使用任何HTML標記,則意味着您可以像下面的代碼那樣在PHP腳本中運行JavaScript。

echo "<div id='popup_upload'></div>"; 
echo "<script type='text/javascript'>document.getElementById('popup_upload').style.display = 'none';alert('upload correct file type');</script>"; 

然後只有腳本可以找到HTML行中提到的id。更好的是,您可以在PHP中返回錯誤消息並將其顯示在前端HTML文件中。

相關問題