dongxia1390 2019-01-22 12:44
浏览 42

用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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大