'', 'medium' => 'm/', 'big' => 'b/') ; foreach($array_folder as $key => $value){ $temp_file = 'uploads/'.$folder.'/'.$value.$file ; $filename = $_SERVER['DOCUMENT_ROOT'].'/'.$temp_file ; //this is the original file $source = imagecreatefromjpeg($filename) or notfound() ; $rotate = imagerotate($source, $degrees, 0) ; imagejpeg($rotate,$filename) ; //save the new image imagedestroy($source) ; //free up the memory imagedestroy($rotate) ; //free up the memory $array[$key] = PATH.$temp_file.'?timestamp='.time() ; $result = 'success' ; } } } $array['result'] = $result ; echo json_encode($array) ; ?>