php_fileupload

 https://www.geeksforgeeks.org/php-explode-function/

https://www.geeksforgeeks.org/php-explode-function/

https://code.tutsplus.com/tutorials/how-to-upload-a-file-in-php-with-example--cms-31763


<form action="actionpage.php" method="post" enctype="multipart/form-data">
        <label for="myfile">select file</label>
        <input type="file" name="myfile" id="myfile" multiple>
       <button name="upload" value="upload" >upload</button>
       
    </form>
<?php
$D=$_FILES['myfile'];
//print_r($D);
$file_name=$_FILES['myfile']['name'];
$file_type=$_FILES['myfile']['type'];
$file_size=$_FILES['myfile']['size'];
$file_tmpname=$_FILES['myfile']['tmp_name'];
//echo $file_tmpname;
$fileNameCmps = explode("."$file_name);

//print_r($fileNameCmps) ;
    $fileExtension = strtolower(end($fileNameCmps));
    //$newFileName=$file_name.'.'.$fileExtension;
    $allowedfileExtensions = array('jpg''gif''png''zip''txt''xls''doc');
    if(in_array($fileExtension,$allowedfileExtensions)){
        $uploadFileDir = 'uploaded_files/';
      $dest_path = $uploadFileDir . $file_name;
      echo $dest_path;
      if(move_uploaded_file($file_tmpname$dest_path)) 
      {
        $message ='File is successfully uploaded.';
      }
      else
      {
        $message = 'There was some error moving the file to upload directory. Please make sure the upload directory is writable by web server.';
      }
    }
    else
    {
      $message = 'Upload failed. Allowed file types: ' . implode(','$allowedfileExtensions);
    }
?>

Comments

Popular posts from this blog

interview questions js[ Anurag Singh ProCodrr]

reactnative_creation