1

I'm trying to insert images in my Excel using the PHPExcel_Worksheet_Drawing of PHPExcel (in this Symfony Bundle) but I get this message all the time:

File http://benefest.local/uploads/persons/image/58af244d3f58c_16143190_10210682923503464_8658615512523719175_n.jpg not found!

Here is my code:

$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setPath($path);
$objDrawing->setWidth(30);
$objDrawing->setCoordinates('A1');
$objDrawing->setWorksheet($phpExcelObject->getActiveSheet());

My images are uploaded by VichUploaderBundle, and I'm generating the absolute path through a function. which returns me http://benefest.local/uploads/persons/image/58af244d3f58c_16143190_10210682923503464_8658615512523719175_n.jpg

In a browser, this image is displayed!

Any clue?

VinZ
  • 360
  • 3
  • 18
  • 1
    Do you realize a difference between a URI and a file path? What function returns you is a URI which can be used to access the image via a web server. But you need a path to the file within your filesystem, so php can read it. – ozahorulia Feb 22 '18 at 12:50
  • Thanks, I've also tried with the path only and I get the same error `File /uploads/persons/image/58af244d3f58c_16143190_10210682923503464_8658615512523719175_n.jpg not found!` – VinZ Feb 22 '18 at 13:14
  • 1
    OK, I found the solution by setting the path to `./uploads/persons/image/58af244d3f58c_16143190_10210682923503464_8658615512523719175_n.jpg`! – VinZ Feb 22 '18 at 13:19

1 Answers1

1

Answer is based on my comments to this question.

There is a difference between URI and file path:

  • URI - used in browser, or being more general in HTTP protocol to get access to some resource via web-server
  • File path - a link to some file within filesystem on your server/computer/etc.

Your function returns a URI string (http://benefest.local/uploads/persons/image/58af244d3f58c_16143190_10210682923503464_8658615512523719175_n.jpg), which can be used to access the image via a web server.

But PHPExcel_Worksheet_Drawing as well as other libraries use PHP's filesystem functions to get access to some file locally. So you need to get a local file path, instead of URI (in you case it is ./uploads/persons/image/58af244d3f58c_16143190_10210682923503464_8658615512523719175_n.jpg).

ozahorulia
  • 9,798
  • 8
  • 48
  • 72