blob 형식의 데이터베이스에서 파일을 다운로드하는 방법. 이미 이미지에서 blob로 파일을 저장하고 있습니다. 그러나 나는 다시 이미지에 들어가는 것을 모른다. 이미 기능 다운로드하지만 작동하지를 만들 수있어blob을 파일로 변환 한 다음 다운로드하십시오.
..
삽입 기능 내 코드에서 누락 무엇
public funtion upload(){
$name = $_FILES['file']['name'];
$size = $_FILES['file']['size'];
$type = $_FILES['file']['type'];
$from = $_FILES['file']['tmp_name'];
//need to get the content of the file
$fp = fopen($from, 'r');
$file_content = fread($fp, filesize($from));
$file_content = bin2hex($file_content);
fclose($fp);
$insertFile = "insert into tb_file (name,content,type,size) VALUES ('$name','$file_content','$type','$size')";
}
다운로드 기능
public function download(){
$this->load->helper('download');
$id_file = $this->uri->segment(3);
$path = base_url()."images/tmp";
$this->load->database();
$show = "select * from tb_file where id_file = ".$id_file.";
$row = $this->db->query($show)->row();
$image = $row->content;
$name = $row->name;
$type = $row->type;
$size = $row->size;
$data = file_put_contents($path."/".$name, base64_decode($image));
header($type);
force_download($name, $data);
}
? 그것은 다운로드입니다하지만이없는 크기
참고 : CodeIgniter의 프레임 워크
당신은 더 나은 당신이 우리가 – RiggsFolly
감사합니다 2 processess을 비교할 수 있습니다 첫번째 장소에있는 데이터베이스에 파일을 저장하는 방법을 우리에게 보여했다. 나는 이미 이미지 삽입 기능을 보여주고있다. – Stfvns
Errrr 이미지를 저장할 때'bin2hex()'를 사용하고 그것을 읽을 때'base64_decode()'를 사용하겠습니까? 그들은 전혀 똑같은 것이 아닙니다 – RiggsFolly