Skip to main content

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>

Comments

Popular posts from this blog

How to check date format in PHP?

Check date format in PHP function isCorrectDateFromat($date){     if(!empty($date)){         $dateString = $date; // Replace this with your date string         $format = "Y-m-d"; // Replace this with your expected date format         $dateTime = DateTime::createFromFormat($format, $dateString);         if ($dateTime === false) { /*             echo "The date is not in the correct format."; */         } else {             $errors = DateTime::getLastErrors();             if (empty($errors)) { /*                 echo "The date is in the correct format."; */                 return true;             } else { /*                 echo "...