2016-08-25 8 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

可能な複製を追加するchdir()機能を使用することができます[オープンに失敗しました。ストリーム:そのようなファイルやディレクトリ](http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory) –

答えて

0

でも、このエラーがmaxUpload.class.phpが同じフォルダ内にあることを確認し、ファイルへの間違ったパスを与えていることを示しています。このファイルの場所をrequire()関数への正しいパスを与える必要があります。

またecho getcwd();ようgetcwd()

Gets the current working directory.に何かを使用することができます。あなたは私があなたのフォルダ構造を知らない正しいパスchdir("../");

を与えることによって、特定のフォルダに移動しますが、の

require '../maxUpload.class.php'または

require '/maxUpload.class.php'

+0

ありがとうArchish。 require()内のmaxUpload.class.phpとupload.phpは、adminのような同じフォルダにあります。私は、最近、これを経験し始めて、「../maxUpload.class.php」を必要としていても、 – Yomi

関連する問題