added exception control to file_get_contents error
This commit is contained in:
parent
46b7bea097
commit
a89e4c93a7
|
|
@ -12,10 +12,14 @@
|
|||
<p>Ordered (numbered) list:</p>
|
||||
<ol><li>Item 1</li><li>Item 2</li></ol>
|
||||
|
||||
|
||||
<p style="line-height:2">Double height</p>
|
||||
|
||||
<h2>Includes images</h2>
|
||||
<img src="https://phpword.readthedocs.io/en/latest/_images/phpword.png" alt=""/>
|
||||
|
||||
<img src="https://localhost/gev/desarrollo/actividades/pruebas_14/5b064503587f7.jpeg" name="Imagen 12" align="bottom" width="208" height="183" border="0"/>
|
||||
<img src="http://localhost/gev/desarrollo/actividades/pruebas_14/5b064503589db.png" name="Imagen 13" align="bottom" width="143" height="202" border="0"/>
|
||||
<img src="http://localhost/gev/desarrollo/actividades/pruebas_14/5b0645035aac8.jpeg" name="Imagen 14" align="bottom" width="194" height="188" border="0"/>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -655,6 +655,7 @@ class Html
|
|||
break;
|
||||
}
|
||||
}
|
||||
$origin_src= $src;
|
||||
if (strpos($src, 'data:image') !== false) {
|
||||
$tmpDir = Settings::getTempDir() . '/';
|
||||
|
||||
|
|
@ -678,7 +679,7 @@ class Html
|
|||
}
|
||||
|
||||
if (!is_file($src)) {
|
||||
if ($imgBlob = file_get_contents($src)) {
|
||||
if ($imgBlob = @file_get_contents($src)) {
|
||||
$tmpDir = Settings::getTempDir() . '/';
|
||||
$match = array();
|
||||
preg_match('/.+\.(\w+)$/', $src, $match);
|
||||
|
|
@ -690,7 +691,12 @@ class Html
|
|||
fclose($ifp);
|
||||
}
|
||||
}
|
||||
$newElement = $element->addImage($src, $style);
|
||||
|
||||
if (is_file($src)){
|
||||
$newElement = $element->addImage($src, $style);
|
||||
}else{
|
||||
throw new \Exception("Could not load image $origin_src");
|
||||
}
|
||||
|
||||
return $newElement;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -519,6 +519,20 @@ class HtmlTest extends \PHPUnit\Framework\TestCase
|
|||
$this->assertTrue($doc->elementExists($baseXpath . '/w:pict/v:shape'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test parsing of remote img that can be found locally
|
||||
*/
|
||||
public function testCouldNotLoadImage()
|
||||
{
|
||||
$src = 'https://fakedomain.io/images/firefox.png';
|
||||
$this->expectException(\Exception::class);
|
||||
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
$section = $phpWord->addSection();
|
||||
$html = '<p><img src="' . $src . '" width="150" height="200" style="float: right;"/></p>';
|
||||
Html::addHtml($section, $html, false, true);
|
||||
}
|
||||
|
||||
public function testParseLink()
|
||||
{
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
|
|
|||
Loading…
Reference in New Issue