phppowerpoint : setPath() - Issue while having space in image name

424 views Asked by At

I am using following code and getting issue if there is an space in image name. And the issue is basically file is not loading at popwerpoint slide.

like:

$shape->setPath("C:/image/abc1.jpg");  // Working fine

$shape->setPath("C:/image/abc 1.jpg"); // Not working due to space in filename

I'm using the PHPPowerPoint class for generating powerpoint slides.

How do I get this to work?

EDIT

For the benefit of roine

public function setPath($pValue = '', $pVerifyFile = true) {
    if ($pVerifyFile) {
        if (file_exists($pValue)) {
            $this->_path = $pValue;

            if ($this->_width == 0 && $this->_height == 0) {
                // Get width/height
                list($this->_width, $this->_height) = getimagesize($pValue);
            }
        } else {
            throw new Exception("File $pValue not found!");
        }
    } else {
        $this->_path = $pValue;
    }
    return $this;
}
2

There are 2 answers

0
Fluffeh On

Try:

$shape->setPath("C:/image/abc%201.jpg");

If that works, you can use a simple string replace.

3
Jonathan de M. On

Try

$file_path = "C:/image/abc 1.jpg";
$clean_file_path = str_replace(" ", "%20", "$file_path");
$shape->setPath($clean_file_path);