How to upload images from my directory into my wordpress?

I’m doing a paste the link onto input and then uses PHP(imagecrop) to crop and store the image onto server directory.

$imagesrc = $_GET['img'];
$img = file_get_contents($imagesrc);

$im = imagecreatefromstring($img);

$width = imagesx($im);

$height = imagesy($im);

$newwidth="400";

$newheight="800";

$thumb = imagecreatetruecolor($newwidth, $newheight);

imagecopyresized($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

$filename = basename($imagesrc);
imagejpeg($thumb,'image/'.$filename); //save image as jpg
imagedestroy($thumb); 
imagedestroy($im);

My question is how to upload images that is stored in the directory into wordpress? I know how to do it using <form> using manually but no idea how to do it after successfully cropping the image then upload to wordpress database automatically.

Update:

Tried uploading or saving it to wp-content\uploads and then I looked up in to wp-admin/upload.php and the images that I uploaded is not showing there.

1 Answer
1

I think this will be helpful for you. It has describe everything step by step and there are part 1 & 3 of that tutorial series. Follow them as well.
Creating a WordPress Plugin Part 2: Uploading Media and using Web Services

Leave a Comment