pathinfo with cakephp

Asked

Viewed 42 times

0

Hello, I made an image upload system, in which, saved images, are saved with $id_o.$extensao = 1_o.jpg , now, I am creating an element, that with this image name, return me the relative path of this image, the problem is that my pathinfo(dirname) is returning me only one ' . '(dot), if anyone can give me a light. I thank you already.

foreach ($fotos as $valor => $foto){
    $extension = pathinfo(WWW_ROOT . 'files' . DS . 'galeria' . DS . "{$foto['Foto']['id']}_o.{$foto['Foto']['extension']}",PATHINFO_DIRNAME);
    echo $extension;
}   
  • The second attribute, PATHINFO_DIRNAME, will return the current directory, which in fact is a ., since you only passed the image name. If you want the relative path, you need to pass all the way in the first parameter.

  • Okay, I changed the question, but in this case, this is the only way to get the relative path, if in the case, I don’t know which folder that file is, there’s no other way to get that path?

  • Well, with that, your code already works the way you expect it to. It will return to you exactly what you passed in the first parameter, except the file name. There’s no other way to know, just with the file name, that you know the rest of the way. You would have to scan all your directory to fetch that file, which would be impractical in my view.

  • Just one more thing, how would I mount a <img src> with echo, using this information? $extension = pathinfo(WWW_ROOT . 'files' . DS . 'galeria' . DS . "{$foto['Foto']['id']}_o.{$foto['Foto']['extension']}",PATHINFO_DIRNAME); In this case the image name is already there too..

  • Experiment with echo $this->Html->image(WWW_ROOT . 'files' . DS . 'galeria' . DS . "{$foto['Foto']['id']}_o.{$foto['Foto']['extension']}", array('fullBase' => true));.

  • The path that it is returning, since the folder www/var/..., is not appearing message, but I tried to put the direct folder, which is /files/gallery/$img, and the image appeared..

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.