如何解决远程服务器上丢失的文件

时间:2016-08-25 04:03:33

标签: php

我需要你的帮助。任何时候我通过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);
        }

    }

}
?>

1 个答案:

答案 0 :(得分:0)

您的文件不会丢失,此错误还表示您提供了错误的文件路径,请确保maxUpload.class.php位于同一文件夹中。您需要提供require()函数的正确路径以找到此文件的位置。

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

echo getcwd();这样的东西。您可以使用chdir()功能通过提供正确的路径chdir("../");

转到特定文件夹

我不知道您的文件夹结构,但添加

require '../maxUpload.class.php'

require '/maxUpload.class.php'