使用file_put_contents将图像添加到MS word文档但是文件已损坏 [英] Image added to MS word document using file_put_contents but gives file corrupted error

查看:253
本文介绍了使用file_put_contents将图像添加到MS word文档但是文件已损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的客户想要一个网页,只需点击一下按钮就可以输入存储在MS Word文档的MySQL数据库表中的图像(照片)。以下是CodeIgniter中的代码:

模型

< pre lang =PHP><?php

类user_model扩展CI_Model {

函数getImage($ EmpId){
$ this - > db - > select('Employee_Id','Employee_Photo');
$ this - > db - >从(雇员);
$ this - > db - > where('Employee_Id',$ EmpId);
$ this - > db - >限制(1);

$ query = $ this - > db - >得到();

if($ query - > num_rows()== 1){
return $ query-> result();
} else {
返回false;
}
}
}
?>









控制器



  $ FullPath_with_File  = $ data ['  full_path'];  //  带路径的MS Word文件 

$ result = $ this-> user_model-> getImage($ session_data [' Emp_Id ]);

foreach($ result as $ row)
{
$ data [' Emp_Photo'] = $ row-> Employee_Photo;
}
file_put_contents($ FullPath_with_File,$ data [' Emp_Photo'], FILE_APPEND);







一切正常。没有错误。但是,当我打开MS Word文件时,它会警告文件已损坏,您要恢复吗?如果回答是,则只有在您信任的情况下才会选择是。回答是后,没有显示任何内容。



我希望图像显示在word文档中。我整整一个星期都在搜索互联网,文章甚至是MS Word的内部。甚至没有一个提示如何识别MS Word的图像。



请帮助我。



我尝试了什么:



我整整一周都在搜索互联网,文章甚至是MS Word的内部结构。甚至没有一个提示如何通过MS Word识别图像。

解决方案

EmpId){


this - > db - > select('Employee_Id','Employee_Photo');


this - > db - >从(雇员);

Our customer wants a web-page that allows to enter image (photograph) stored in MySQL database table in MS Word document by just clicking a button. Following is the code in CodeIgniter:

Model

<pre lang="PHP"><?php

Class user_model extends CI_Model {

    function getImage($EmpId) {
       $this -> db -> select('Employee_Id', 'Employee_Photo');
       $this -> db -> from('Employees');
       $this -> db -> where('Employee_Id', $EmpId);
       $this -> db -> limit(1);

       $query = $this -> db -> get();

       if($query -> num_rows() == 1)  {
           return $query->result();
       }   else   {
                  return false;
                  }
       }
  }
?>





Controller

$FullPath_with_File = $data['full_path'];    // MS Word file with path

$result = $this->user_model->getImage($session_data['Emp_Id']);

foreach($result as $row)
{
    $data['Emp_Photo'] = $row->Employee_Photo;
}
file_put_contents($FullPath_with_File, $data['Emp_Photo'], FILE_APPEND);




Everything works fine. No-error. However, when I open the MS Word file it warns that file is corrupted, Do you want to recover? If asnwered 'yes', it asks select yes only if you trust. After answering 'yes', nothing is shown.

I want the image to be displayed in the word document. I spent entire week in searching internet, articles and even internals of MS Word. There is not even a single hint how image is recognised by MS Word.

Please help me.

What I have tried:

I spent entire week in searching internet, articles and even internals of MS Word. There is not even a single hint how image is recognized by MS Word.

解决方案

EmpId) {


this -> db -> select('Employee_Id', 'Employee_Photo');


this -> db -> from('Employees');


这篇关于使用file_put_contents将图像添加到MS word文档但是文件已损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆