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文件夹中创建。但现在我想

  1. read the content of tmp directory
  2. 读取tmp目录的内容

  3. Generate the url of tmp image file
  4. 生成tmp图像文件的URL

  5. Send that src as a response back to ajax call
  6. 将该src作为响应发送回ajax调用

Javascript:

$.ajax({
    url: PAdmin.roateImageUrl,
    data: {
        mediaId: id[1],
        src: src
    },
    type: 'POST',
    success: function(response) {
        img.attr('src', response);
    }
});
  1. Show that rotated image to end user before uploading on S3 server.
  2. 在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工作,但可能有点资源昂贵

更多相关文章

  1. PHP获取服务器端的相关信息
  2. 使用ajax在服务器端恢复json时出错
  3. 在PHP中将PDF文档转换为预览图像,而无需安装Ghostscript
  4. php清理当前目录下的指定文件和空目录(源码),建议服务器端执行
  5. Codeigniter在localhost中的url上没有index.php但在服务器中没有
  6. 自动同步vps服务器或本地文件的数据到百度网盘
  7. SQL调优案例,MYSQL服务器CPU100%问题解决
  8. 阿里云服务器远程连接mysql
  9. Ubuntu+Django+Nginx+uWSGI+Mysql搭建Python Web服务器

随机推荐

  1. PHP读取word文档的方法分析
  2. PHP 进程池与轮询调度算法实现多任务
  3. PHP -FPM是什么?有什么特点?
  4. PHP中16个高危函数
  5. PHP中的递归是什么?实现方式有哪些?
  6. PHP中self与this关键字的区别
  7. PHP7新特性总结
  8. PHP创建对象的6种方式
  9. php如何处理大数据高并发
  10. PHP常见安全问题及解决方法