Show images from temp directory to end users
16lz
2021-01-22
I am doing image rotate functionality. I am rotating the image and saving into tmp directory using
我正在做图像旋转功能。我正在旋转图像并使用保存到tmp目录中
$rotate = imagerotate($source, 90, 0);
$rotatedTmpFile = tempnam('/tmp', 'rotatedThumbnailImage');
imagejpeg($rotate, $rotatedTmpFile ,100);
Files get created in tmp folder. But now I want to
文件在tmp文件夹中创建。但现在我想
- read the content of tmp directory
- Generate the url of tmp image file
- Send that src as a response back to ajax call
读取tmp目录的内容
生成tmp图像文件的URL
将该src作为响应发送回ajax调用
Javascript:
$.ajax({
url: PAdmin.roateImageUrl,
data: {
mediaId: id[1],
src: src
},
type: 'POST',
success: function(response) {
img.attr('src', response);
}
});
- Show that rotated image to end user before uploading on S3 server.
在S3服务器上载之前向最终用户显示旋转的图像。
Please help.
3 个解决方案
#1
2
I'm pretty sure /tmp is not accessible via your webserver directly. You should either move from /tmp to a directory in your docroot, or alternatively encode the image in the html directly; using
我很确定/ tmp无法直接通过您的网络服务器访问。您应该从/ tmp移动到docroot中的目录,或者直接在html中编码图像;运用
$mime = mime_content_type($rotatedTmpFile);
$data = file_get_contents($rotatedTmpFile);
exit('data:' . $mime . ';base64,' . base64_encode($data));
this should work as an image-src but might be somewhat resource-expensive
这应该作为image-src工作,但可能有点资源昂贵
更多相关文章
- PHP获取服务器端的相关信息
- 使用ajax在服务器端恢复json时出错
- 在PHP中将PDF文档转换为预览图像,而无需安装Ghostscript
- php清理当前目录下的指定文件和空目录(源码),建议服务器端执行
- Codeigniter在localhost中的url上没有index.php但在服务器中没有
- 自动同步vps服务器或本地文件的数据到百度网盘
- SQL调优案例,MYSQL服务器CPU100%问题解决
- 阿里云服务器远程连接mysql
- Ubuntu+Django+Nginx+uWSGI+Mysql搭建Python Web服务器