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.";
}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s