23 September 2021

How to upload file in selected folder in PHP in Wordpress?

Upload file in selected folder in PHP in Wordpress. 


   <?php

   //echo $folder =  get_stylesheet_directory_uri();

  // echo $_SERVER["DOCUMENT_ROOT"];

 extract($_POST);

 global $wpdb;

 if(isset($_POST['submit'])){

 

$filename = $_FILES["file"]["name"];

$ext = pathinfo($filename, PATHINFO_EXTENSION);

$encrypt_file= md5(str_replace(" ", "_", $filename).date("Y-m-d-h-i-s"));

$realpath = $encrypt_file.'.'.$ext;

   $tempname = $_FILES["file"]["tmp_name"];

   echo $folder =  $_SERVER["DOCUMENT_ROOT"]."/raising/wp-content/themes/twentytwenty-child/img/".$realpath;

   //echo $folder =  get_stylesheet_directory_uri()."/img/".$filename;

   move_uploaded_file($tempname,$folder);

   

 

 }


if(!empty($folder)){

?>

<img src="<?php echo get_stylesheet_directory_uri()."/img/".$realpath; ?>" width="400" height="400">

<?php

}

?>

<form action="" method="post" enctype="multipart/form-data" >

<input type="file" name="file" id="file" class="form-upl">

<input type="submit" name="submit" value="Submit">

</form>

No comments:

Post a Comment

How to add re-captcha v3 on all Elementor forms using coding?

 Add re-captcha v3 on all Elementor forms using coding add_action('wp_footer',function(){     ?> <script src="https://www...