-1

Please i need your help on this. Any time i transfer this file into remote server through ftp, it often get missing on the server somehow. I always have to re-upload it. Recently all i get are errors like this PHP Warning: require(maxUpload.class.php): failed to open stream: No such file or directory. I know the errors are due to due to my require() function. Is there any reason this file keep getting lost on the remote server?

<?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> 

This is 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);
        }

    }

}
?>
Yomi
  • 63
  • 1
  • 2
  • 6
  • Possible duplicate of [Failed to open stream : No such file or directory](http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory) – Vic Seedoubleyew Aug 27 '16 at 08:54

1 Answers1

0

Your file is not missing, this error also indicate that you are giving wrong path to the file, make sure maxUpload.class.php is in same folder. you need to give correct path to require() function where to locate this file.

You can also use getcwd() to Gets the current working directory.

something like echo getcwd();. you can use chdir() function to go to specific folder by giving correct path chdir("../");

i don't know your folder structure but add

require '../maxUpload.class.php' or

require '/maxUpload.class.php'

Archish
  • 850
  • 8
  • 32
  • Thanks Archish. both maxUpload.class.php and upload.php inside which is require() are in the same folder like admin. It was working initially until i started experiencing this lately even with require '../maxUpload.class.php' – Yomi Aug 25 '16 at 05:54