How to upload image in wordpress
if(isset($_POST['submit'])&&$_POST['submit']=='SUBMIT'){ //This is the directory where images will be saved $target = WP_CONTENT_DIR."/upload/";
you have to create folder name upload in root directory(path: wp-content/upload/..)
$target = $target . basename($_FILES['photo']['name']); //This gets all the other information from the form // Connects to your Database $file_size = $_FILES['photo']['size']; //['photo'] is name of input type 'file' in form $file_type = $_FILES['photo']['type']; if (($file_size > 200000000)){ echo $message = 'File too large. File must be less than 200 kb.'; } else{ ( ($file_type != "image/jpeg") && ($file_type != "image/jpg") && ($file_type != "image/gif") && ($file_type != "image/png") ) } if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //success message... } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; }
Leave a Comment
You must be logged in to post a comment.