title: PHP file upload Issues - Can't Move uploaded File
body: <p>I am trying to upload image to database and getting this PHP error message:</p>
  
  <blockquote>
    <p>Warning: move_uploaded_file(/upload/efc5ad334bca9f31b19d85a6cc2ada57/-416649605.jpg): failed to open stream: No such file or directory in C:\xampp\htdocs\learnphp\gettingstarted.php on line 51</p>
    
    <p>Warning: move_uploaded_file(): Unable to move 'C:\xampp\tmp\phpA9E6.tmp' to '/upload/efc5ad334bca9f31b19d85a6cc2ada57/-416649605.jpg' in C:\xampp\htdocs\learnphp\gettingstarted.php on line 51
        Upload Fail.</p>
  </blockquote>
  
  <p>Here is my php script:</p>
  
  <pre><code>&lt;?php
  require("include/functions.php");
  check_session();
  
  $logged_user = $_SESSION['username'];
  
  if(isset($_FILES['avator']['name']) &amp;&amp; $_FILES['avator']['tmp_name'] !=""){
  
  
      //setting file properties
      $fileName = $_FILES['avator']['name'];
      $filetmpLoc = $_FILES['avator']['tmp_name'];
      $fileType = $_FILES['avator']['type'];
      $filesize = $_FILES['avator']['size'];
      $fileErrMsg = $_FILES['avator']['error'];
  
      //explose the filename extention into an array
      $kaboom = explode('.',$fileName);
      $fileExt = end($kaboom);
      list($width ,$height) = getimagesize($filetmpLoc);
      if( $width &lt;10 || $height &lt;10 ){
  
          //the image has not dimenssion
          echo 'The Image has no dimension.Try again!';
          exit();
  
  
          }else{
              // The image is has dimension so its OK
  
              $db_file_name = rand(100000000000,999999999999).".".$fileExt;
              //check the size of the image
              if($filesize &gt; 1048576){
  
                  echo 'Your avator file size was larger than 1mb.';
                  exit();
  
                  }else if(!preg_match('/\.(gif|png|jpg)$/i',$fileName)){
                      echo"Your avator file was not JPG,PNG or GIF type.Try again.";
                      exit();
  
                      }else if($fileErrMsg == 1){
  
                          echo "Unknoan Error occured. Upload Fail.";
                          exit();
  
                          }
  
  
                          //move uploaded avator
                  $moveResult = move_uploaded_file( $filetmpLoc,"/upload/$logged_user/$db_file_name");
                  if( $moveResult !=true){
  
                      echo 'Upload Fail.';
                      exit();
  
                      }else{
  
                          //resize the image
                          include_once("include/resizeimage.php");
                          $target_file = "user/$logged_user/$db_file_name";
                          $resize_file ="user/$logged_user/$db_file_name";
                          $wmax = 200;
                          $hmax = 230;
                          img_resize($target_file,$resize_file,$wmax,$hmax,$fileExt);
                          $sql = "UPDATE mygust SET avatar = '$db_file_name' WHERE username='$logged_user' LIMIT 1";
                          $query = mysqli_query($con,$sql);
                          mysqli_close($con);
                          exit();
  
  
  
                          }
  
  
              }
  
  
      }
  
   ?&gt;
  </code></pre>
  
  <p>My HTML code is:</p>
  
  <pre><code>   &lt;form id="u_pro_pic" method="post" enctype="multipart/form-data" onSubmit="" action="&lt;?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?&gt;"&gt;
  &lt;h2&gt;Set your Profile Avator&lt;/h2&gt;&lt;br&gt;
  
  &lt;div id="av_wrap"&gt;&lt;div id="avator_div"&gt;&lt;img src="image/blank-profile.png" class="avator" title="Chose a file to upload"  onClick="triggerUpload(event,'avator')"&gt;&lt;/div&gt;
  &lt;div id="ad_clarleft"&gt;
  &lt;input type="button" class="add" title="Choose a file to upload"  onClick="triggerUpload(event,'avator')" value="Add Avator"&gt;&lt;br&gt;
  &lt;hr&gt;
  &lt;p&gt;These brethren have uploaded their's and you should too. &lt;/p&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  
  
  
  &lt;input name="avator" type="file" id="avator" form="u_pro_pic" onChange="readURL(this)"&gt;
  &lt;input type="submit" name="u_avator" id="sumit" class="avt" value="Upload"&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>Please any help would be much appreciating.</p>