2016-07-11 7 views
0

画像以外のファイルをアップロードしようとしたときにポップアップウィンドウを非表示にしたいのですが、ポップアップボックスに写真のアップロードボタンをクリックしてシンボルと実行は、私はエラーを取得する私のcode.inコンソールはdefined.please PHPスクリプトで事前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のヘルプが必要な場合は、PHPスクリプトではなく、生成されたHTMLファイル(ブラウザの表示/ソースから)を表示してください。そのようにしてJavascriptを知っている人は誰でも、私たちの頭の中でPHPを実行する方法がわからないので、実際にブラウザで何が実行されているのかを見ることができます。 – jfriend00

答えて

0

に...私にすべてのおかげで、この問題の解決策を与えないpopup_uploadされるstatement.hereで停止します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ファイルで表示できます。