用php编写base64文件时出错403

I'm trying to decode a base64 string and write it to a file:

<?php
    // requires php5
    define('UPLOAD_DIR', '/images/');
    $img = $_POST['img'];
    $img = str_replace('data:image/png;base64,', '', $img);
    $img = str_replace(' ', '+', $img);
    $data = base64_decode($img);
    $file = UPLOAD_DIR . uniqid() . '.png';
    $success = file_put_contents($file, $data);
    print $success ? $file : 'Unable to save the file.';
?>

But the server gives this error message:

403 Forbidden

You don't have permission to access testupload.php on this server

I have set all permissons for the php file and the images directory, so I don't understand why I get this error.

When I put the decoded string of image directly inside the $img variable, it works and it creates the file under the images folder... But when I try to post the decoded string it doesn't work.

How can I solve this?

NOTE : when we try to send decoded string of image it may contain some virus or something like that from hackers ... i contact with my host providers and they say if you want we can turn of the modsecurity but its really unsafe way to do ... so what i have to do with this situation?