0

I am trying on upload file from local file system to a remote server using php.

I am using move_uploaded_file function but when i select a file on my local file system, it tries to find the file on remote server and hence fails. maybe i am missing something. Let's say if i am trying to upload a file from C:\Data\abc.txt. It tries to find the file on /server/abc.txt and hence fails to upload the file. Please let me know if i am missing something.

<?
    if(isset($_FILES['image'])){
        $errors= array();
        $file_name = $_FILES['image']['name'];
        $file_size =$_FILES['image']['size'];
        $file_tmp =$_FILES['image']['tmp_name'];
        $file_type=$_FILES['image']['type'];
        $original = $root_path .$file_name; 

        echo $_FILES['image']['tmp_name'];

        if($file_size > 100097152){
            $errors[]='File size must be less than 100 MB';
        }

        if(empty($errors)==true){
            move_uploaded_file($file_tmp, '/uploads');
            echo "Success";
        }else{
            print_r($errors);
        }
    } 
?>
<html>
   <body>

      <form action="" method="POST" enctype="multipart/form-data">
         <input type="file" name="image" />
         <input type="submit"/>
      </form>

   </body>
</html>
0

3 Answers 3

1

I dont know if I have understood you correctly, but you means with remote server your webserver? This server doesnt access your file system directly because of your browser's sandbox mode. It gets only the submitted file, the origin path doesnt matter.

The second parameter of the function move_uploaded_file has to be the target file, not the target dictionary.

Example:

move_uploaded_file($file_tmp, '/uploads/' . $file_name);
Sign up to request clarification or add additional context in comments.

1 Comment

Yes that was the issue :) a silly mistake from my end. Thank you so much :)
1

diffcult to answer pls tell me the php version and as a hint: have you checked is_uploaded_file() php.net/manual/function.is-uploaded-file.php

Comments

1

could help to use the error/status-reporting in $_FILES['image']['error'] - gives feedback on error/status code of your file upload, so you can better understand what the source of the problem possibly is:

0 = success
1 = file too big (php.ini set)
2 = file too big (max file size directive)
4 = no file was uploaded
6 = no access to temp folder on server
7 = file could not be written to server
8 = upload stopped by a php extension

hope that helps

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.