javascript - 从 blob-url 保存图像(javascript / php)
问题描述
使用 pdf-js 我过滤 PDF 文件的图像。在此之后,我在一个 div 中显示所有图像。元素如下所示:
<img src="blob:http://myhost/07eee62c-8632-4d7f-a086-c06f1c920808">
我想做的是将所有这些图像保存在服务器的目录中。但我不知道该怎么做。
我试过这个,但我认为这是完全错误的:
let form_data = new FormData();
fetch(url)
.then(res => res.blob()) // Gets the response and returns it as a blob
.then(blob => {
// Here's where you get access to the blob
// And you can use it for whatever you want
// Like calling ref().put(blob)
// Here, I use it to make an image appear on the page
let objectURL = URL.createObjectURL(blob);
let myImage = new Image();
myImage.src = objectURL;
console.log(id, url, selectedProject, pdfName);
form_data.append('file', myImage);
form_data.append('path', dest);
form_data.append('project', selectedProject);
form_data.append('url', url);
});
$.ajax({
url: 'upload_referenceFile.php',
dataType: 'text',
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
success: function (php_script_response) {
}
});
php:
$project = $_REQUEST['project'];
$script = $_REQUEST['path'];
$dest = 'data/' . $project . '/' . $script . '/media/';
_log($_REQUEST['file']);
$exists = file_exists($dest . $_FILES['file']['name']);
if($exists){
}else{
if (!file_exists($dest)) {
if (!mkdir($dest, 0777, true) && !is_dir($dest)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $dest));
}
}
move_uploaded_file($_FILES['file']['tmp_name'], $dest . $_FILES['file']['name']);
}
解决方案
推荐阅读
- git - 如何通过丢弃所有更改将远程源主分支的所有更改复制到本地的新分支
- reactjs - 反应:未捕获的类型错误:tokenIds.map 不是函数
- linux - pulseaudio:无法初始化 PA contextaudio:无法初始化“pa”音频驱动程序
- android - 操作栏中的 Android 个人资料图片
- javascript - 使用 fetch API 与 PHP 的 CORS “SyntaxError: Unexpected end of input at”
- python-3.x - tensorflow 如何保持 l2_normalize 约束?
- office-js - Windows10 上的 Word 加载项本地侧载问题
- cron - 多个自定义 crontab 文件到一个主 crontab
- azure-aks - AKS 节点池升级失败,Azure 活动日志“操作超时,请重试”。
- python - IndexError:索引 6 超出轴 0 的范围,大小为 6