1
votes
<?php
    if(isset($_FILES['file'])) 
    { 
      
      $original_url='adminPanel/Images/';
      $currentDate = new DateTime();
      $currentTimestamp = $currentDate->format("YmdHis");
      $randomNumber= mt_rand(1111, 9999);
      $filePath=$_FILES['file']['name'];
      $fileName = $currentTimestamp.$randomNumber.$filePath;
      $source = $_FILES['file']['tmp_name'];
      $ext = end((explode(".", $filePath)));//take extension from image/video 
      $fileName = $currentTimestamp.$randomNumber.".".$ext;  
      $original = $original_url.$fileName;  
         move_uploaded_file($source,$original ); 
    }
    
?>

PHP Warning: move_uploaded_file(adminPanel/Images/201704210824047891.JPG): failed to open stream: No such file or directory in G:\PleskVhosts\sinnonteq.com\qhawk.sinnonteq.com\adminPanel\Product.php on line 19

PHP Warning: move_uploaded_file(): Unable to move 'C:\Windows\Temp\phpC5EE.tmp' to 'adminPanel/Images/201704210824047891.JPG' in G:\PleskVhosts\sinnonteq.com\qhawk.sinnonteq.com\adminPanel\Product.php on line 19

1
Most likely the target folder adminPanel/Images/ but is on a different level in the physical file tree.arkascha

1 Answers

1
votes

Sorry for not answering the question before the edit.

Updated answer

It is good practice to check if the files and locations you are you using exist.

You can use is_file() to check if the file exists or is_uploaded_file() to check if the file exists and it is uploaded by HTTP POST if the source file exists.

And you can use is_dir() to check if the target folder exists.

If it does not exist you can create it first with mkdir()