2016-08-25 73 views
-1

請我需要你的幫助。任何時候我通過ftp將這個文件傳輸到遠程服務器,它通常會以某種方式在服務器上丟失。我總是不得不重新上傳它。最近我得到的是這樣的錯誤PHP Warning: require(maxUpload.class.php): failed to open stream: No such file or directory。 我知道這些錯誤是由於我的require()函數。 是否有任何理由讓這個文件在遠程服務器上丟失?如何解決遠程服務器上丟失的文件

<?php 
require '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> 
    <title>Upload Page</title> 
</head> 
<body> 
<?php 
    $myUpload = new maxUpload(); 
    //$myUpload->setUploadLocation(getcwd().DIRECTORY_SEPARATOR); 
    $myUpload->uploadFile(); 
?> 
</body> 

這是maxUpload.class.php

<?php 
class maxUpload{ 
    var $uploadLocation; 
    function maxUpload(){ 
     $this->uploadLocation = getcwd().DIRECTORY_SEPARATOR."/images". DIRECTORY_SEPARATOR; 
    } 
    function setUploadLocation($dir){ 
     $this->uploadLocation = $dir; 
    } 

    function showUploadForm($msg='',$error=''){ 
?> 
     <div id="container"> 

      <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>Upload Image (Jpeg Only) 
          <input name="myfile" type="file" size="30" /> 
         </label> 
         <label> 
          <input type="submit" name="submitBtn" class="sbtn" value="Upload" /> 
         </label> 
        </center> 
       </form> 
      </div> 
     </div> 
<?php 
    } 

    function uploadFile(){ 
     if (!isset($_POST['submitBtn'])){ 
      $this->showUploadForm(); 
     } else { 
      $msg = ''; 
      $error = ''; 
      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']). 
        " <b style='color:white;'>was uploaded successfully!</b>"; 
       } else{ 
        $error = "The upload process failed!"; 
       } 
      } 

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

    } 

} 
?> 
+0

可能的複製[無法打開流:沒有這樣的文件或目錄](http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory) –

回答

0

您的文件不丟失,這個錯誤還表明,你的文件給錯誤的道路,確保maxUpload.class.php是在同一個文件夾。你需要給正確的路徑require()函數在哪裏找到這個文件。

您還可以使用getcwd()Gets the current working directory.

echo getcwd();。您可以使用chdir()功能通過提供正確的路徑chdir("../");

去特定的文件夾,我不知道你的文件夾結構,但增加的

require '../maxUpload.class.php'

require '/maxUpload.class.php'

+0

感謝Archish。這兩個maxUpload.class.php和upload.php都是require()與admin相同的文件夾。它一直在工作,直到我最近開始體驗這個,即使需要'../maxUpload.class.php' – Yomi

相關問題