0

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

In codeigniter I can't download a pdf file from a folder. When trying to download it, in our server it is working but, in client's server is not working. What can be the reason?

This is my code in controller.

$directory = './pdf/';
set_realpath($directory);
$file = $directory.'dwn.pdf';
$fp = fopen($file,'wb');
$pdfcode = "---some texts----";
fwrite($fp,$pdfcode);
fclose($fp);
$data = file_get_contents(base_url()."pdf/dwn.pdf"); // Read the file's contents
$name = 'dwn.pdf';
force_download($name, $data); 

This is the error.

A PHP Error was encountered

Severity: Warning

Message: fopen(./pdf/dwn.pdf) [function.fopen]: failed to open stream: Permission denied

Filename: controllers/pms.php

Line Number: 732
A PHP Error was encountered

Severity: Warning

Message: fwrite() expects parameter 1 to be resource, boolean given

Filename: controllers/pms.php

Line Number: 733
A PHP Error was encountered

Severity: Warning

Message: fclose() expects parameter 1 to be resource, boolean given

Filename: controllers/pms.php

Line Number: 734
Community
  • 1
  • 1
Kichu
  • 3,284
  • 15
  • 69
  • 135

1 Answers1

0

Could it be the file name and/or permisisons, try this modified code

$directory = './pdf/';
set_realpath($directory);
$file = $directory.'dwn.pdf';
chmod($file,0777);
$fp = fopen($file,'wb');
$pdfcode = "---some texts----";
fwrite($fp,$pdfcode);
fclose($fp);
$data = file_get_contents($file); // Read the file's contents
$name = 'dwn.pdf';
force_download($name, $data); 
Andy Gee
  • 3,149
  • 2
  • 29
  • 44