2

I don't know what's wrong with my code. I have Z: network drive named ntserver and i want to move file in it. Only working in a local drive such as C and D.

The error displays :

Warning: move_uploaded_file(\ntserver\test\oggy_and_the_cockroaches-wide.jpg): failed to open stream: No such file or directory in C:\wamp\www\michael\upload1.php on line 30

Warning: move_uploaded_file(): Unable to move 'C:\wamp\tmp\php3FDE.tmp' to '\ntserver\test\oggy_and_the_cockroaches-wide.jpg' in C:\wamp\www\michael\upload1.php on line 30

<?
       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'];

          $expensions= array("jpeg","jpg","png");



          if($file_size > 2097152) {
             $errors[]='File size must be exactly 2 MB';
          }

          if(empty($errors)==true) {
             move_uploaded_file($file_tmp,"\\\\ntserver\test\\".$file_name);
             echo "Success";
          }else{
             print_r($errors);
          }
       }
?>
codeSeven
  • 479
  • 5
  • 23
  • try to remove last backslash and change path to move_uploaded_file($file_tmp,"\\\\ntserver\test\".$file_name); or replace the "ntserver" with IP address of machine. Next one tip: try to write to Z:\test as you have mounted that drive as letter Z. You also need to check if permissions are valid and have you mounted drive permanently in windows – Fiil Apr 26 '16 at 06:38
  • @Fiil , yes., i have already tried with Z: and error still the same. i have permission to write a file in Z: – codeSeven Apr 26 '16 at 06:43
  • @Michel make sure the `test` directory exist on remote path and php process has enough rights to write to the path. – jagad89 Apr 26 '16 at 06:44
  • @jagad89 , yes i created a test folder in Z: , what do you mean by enough right to write with php ? how am i supposed to do that. I can write in the Z: test folder – codeSeven Apr 26 '16 at 06:45
  • @MichaelAngeloJopia just right click on the `test` folder-->Properties-->Security tab and give write permission to every user, and try again. – jagad89 Apr 26 '16 at 06:54
  • @jagad89 i have already check it. i have permission to right the file. – codeSeven Apr 26 '16 at 07:06
  • @MichaelAngeloJopia What about the system user rights ? – jagad89 Apr 26 '16 at 09:48
  • 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 Apr 26 '16 at 12:18

1 Answers1

0

Try removing a back slash. Before trying this make sure that the network location is accessible through cli or run.

move_uploaded_file($file_tmp,"\\ntserver\test\".$file_name);
Jijo John
  • 1,375
  • 9
  • 21