【问题标题】:Save Image to IIS Server with XMLHttpRequest and PHP使用 XMLHttpRequest 和 PHP 将图像保存到 IIS 服务器
【发布时间】:2020-12-07 15:39:03
【问题描述】:

我有一个网络应用程序,它允许用户使用网络摄像头拍照,然后将其显示为 HTML 画布。然后画布成功地转换为图像,显示出来,然后使用 XMLHttpRequest 发送到服务器。这个过程发生在以下JS函数被触发时:

function convertCanvasToImage() {
    let canvas = document.getElementById("canvas");
    let image = new Image();
    document.getElementById("profile").src = canvas.toDataURL();
 
    var newName = canvas.toDataURL();
    xhr = new XMLHttpRequest();

    xhr.open('POST', 'saveimage.php');
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xhr.send(encodeURI('imgBase64=' + newName));
}

PHP 代码 saveimage.php 然后处理要保存到服务器的图像:

  define('UPLOAD_DIR', 'uploads/new.png');   
  $img = $_POST['imgBase64'];   
  $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.';  

此过程在本地服务器 (XAMPP) 上完全按预期工作,但在 IIS(Windows Server 2019 上的 IIS10)上运行时,我收到“无法保存文件”。消息。

我假设这是 IIS 的安全问题,但不确定解决方案是否涉及 PHP 标头、IIS 中的 CORS 或完全其他问题。有什么建议吗?

【问题讨论】:

  • 保存前检查目录权限或输出结果
  • 谢谢,编辑目录权限解决了问题

标签: javascript php iis xmlhttprequest


【解决方案1】:

确认这是文件夹权限问题

【讨论】:

  • 您的问题解决了吗?如果解决了,请分享您的答案,以帮助有类似问题的其他人。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-07-26
  • 1970-01-01
  • 2017-11-19
  • 1970-01-01
  • 1970-01-01
  • 2011-09-12
  • 1970-01-01
相关资源
最近更新 更多