无法使用php旋转上传的图像

I try to rotate the uploaded image 90 degrees after uploading, I tried imagerotate() method, but it's not working.

Here is my code:

$tmp = $_FILES['photoimg']['tmp_name']; 
$path = "uploads/";  
move_uploaded_file($tmp, $path."newfile.jpg");  
$rotate = imagerotate($path."newfile.jpg", 90, 0);
imagejpeg($rotate);
imagedestroy($source);
imagedestroy($rotate);

Any help will be greately appreciated, thanks!

imagerotate needs a resource as first parameter not a file path. You should get an error if you'd enable error reporting. error_reporting(E_ALL);

$source = imagecreatefromjpeg($path."newfile.jpg");
$rotate = imagerotate($source, 90, 0);
imagejpeg($rotate);
imagedestroy($source);
imagedestroy($rotate);