Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    25
    Thanks
    3
    Thanked 0 Times in 0 Posts

    changing upload dir

    Thanks for any help it is greatly appreciated.

    This is probably an easy one but I have no idea how to do it.

    In the script below I need to change the upload location dir from temp
    to a dir called uploads. What part do I change please.

    Code:
    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">Maxim Modeling Upload Form</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);
            }
    
        }
    
    }
    ?>

  • #2
    Regular Coder
    Join Date
    Mar 2009
    Location
    United Kingdom
    Posts
    161
    Thanks
    6
    Thanked 28 Times in 28 Posts
    Well i dont think you can change where the file goes initially, you can only move it to a specified folder.

    Look in your text :
    PHP Code:
                    $target_path $this->uploadLocation basename$_FILES['myfile']['name']);

                    if(@
    move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) 
    $target_path i suppose is the path which it moves the file from your server's temp folder and move_uploaded_file, is the script for doing this so just change the $target_path to the destination you wish, but it has to include "$_FILES['myfile']['name']" i think, so it knows what file you are talking about.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •