$parent_post_id=isset($_POST['post_id']) ? $_POST['post_id']:0;// The parent ID of our attachments$valid_formats=array("jpg","png","gif","bmp","jpeg");// Supported file types$max_file_size=1024*500;// in kb$max_image_upload=10;// Define how many images can be uploaded to the current post$wp_upload_dir= wp_upload_dir();$path=$wp_upload_dir['path'].'/';$count=0;

// Check if user is trying to upload more than the allowed number of images for the current postif((count($attachments)+count($_FILES['files']['name']))>$max_image_upload){$upload_message[]="Sorry you can only upload ".$max_image_upload." images for each Ad";}else{