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

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.


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.


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.