2014-03-06 296 views
0

嘿stackoverflow社區我需要隱藏或顯示此腳本時,如果我clik上一些單詞上載或按鈕此腳本disiper或顯示我想要使此腳本隱藏第一次當用戶clik上傳「或此腳本將顯示的按鈕。PHP - 隱藏代碼隱藏div div

這是腳本

<?php require_once("maxUpload.class.php"); ?> 



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 

<head> 

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 

    <title>Upload File</title> 

    <link href="style/style.css" rel="stylesheet" type="text/css" /> 

</head> 



<body> 

<?php 

    $myUpload = new maxUpload(); 

    //$myUpload->setUploadLocation(getcwd().DIRECTORY_SEPARATOR); 

    $myUpload->uploadFile(); 

?> 

</body> 

maxUpload.class.php:

<?php 
/************************************************* 
* Max's File Uploader 
* 
* Version: 1.0 
* Date: 2007-11-26 
* 
****************************************************/ 
class maxUpload{ 
    var $uploadLocation; 

    /** 
    * Constructor to initialize class varaibles 
    * The uploadLocation will be set to the actual 
    * working directory 
    * 
    * @return maxUpload 
    */ 
    function maxUpload(){ 
     $this->uploadLocation = getcwd().DIRECTORY_SEPARATOR; 
    } 

    /** 
    * This function sets the directory where to upload the file 
    * In case of Windows server use the form: c:\\temp\\ 
    * In case of Unix server use the form: /tmp/ 
    * 
    * @param String Directory where to store the files 
    */ 
    function setUploadLocation($dir){ 
     $this->uploadLocation = $dir; 
    } 

    function showUploadForm($msg='',$error=''){ 
?> 
     <div id="container"> 
      <div id="header"><div id="header_left"></div> 
      <div id="header_main">Max's File Uploader</div><div id="header_right"></div></div> 
      <div id="content"> 
<?php 
if ($msg != ''){ 
    echo '<p class="msg">'.$msg.'</p>'; 
} else if ($error != ''){ 
    echo '<p class="emsg">'.$error.'</p>'; 

} 
?> 
       <form action="" method="post" enctype="multipart/form-data" > 
        <center> 
         <label>File: 
          <input name="myfile" type="file" size="30" /> 
         </label> 
         <label> 
          <input type="submit" name="submitBtn" class="sbtn" value="Upload" /> 
         </label> 
        </center> 
       </form> 
      </div> 
      <div id="footer"><a href="http://www.phpf1.com" target="_blank">Powered by PHP F1</a></div> 
     </div> 
<?php 
    } 

    function uploadFile(){ 
     if (!isset($_POST['submitBtn'])){ 
      $this->showUploadForm(); 
     } else { 
      $msg = ''; 
      $error = ''; 

      //Check destination directory 
      if (!file_exists($this->uploadLocation)){ 
       $error = "The target directory doesn't exists!"; 
      } else if (!is_writeable($this->uploadLocation)) { 
       $error = "The target directory is not writeable!"; 
      } else { 
       $target_path = $this->uploadLocation . basename($_FILES['myfile']['name']); 

       if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) { 
        $msg = basename($_FILES['myfile']['name']). 
        " was uploaded successfully!"; 
       } else{ 
        $error = "The upload process failed!"; 
       } 
      } 

      $this->showUploadForm($msg,$error); 
     } 

    } 

} 
?> 
+0

然後你就可以EHM ...等待什麼呢? –

+0

調用'.load()'加載遠程腳本上的按鈕點擊/或任何event.ref:http://api.jquery.com/load/ – dreamweiver

+0

我不會忽略什麼是電子... – user3345725

回答

1

默認隱藏你的上傳表單,並顯示的onclick按鈕。

<body> 
<div id="uploadForm" style="display:none"> 
<?php 
    $myUpload = new maxUpload(); 
    //$myUpload->setUploadLocation(getcwd().DIRECTORY_SEPARATOR); 
    $myUpload->uploadFile(); 
?> 
</div> 
<input type="button" onclick="document.getElementById('uploadForm').style.display='block';"> 
</body> 

如果你想有一個鏈接,而不是按鈕,可以使用

<a href="#" onclick"document.getElementById('uploadForm').style.display='block';return false;">Upload</a> 
+0

非常感謝SajithNair – user3345725

+0

我可以使文本?像一個字? – user3345725

+0

當然,使用鏈接而不是按鈕請參閱我編輯的答案 – SajithNair