2016-07-11 59 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文件中。

相关问题