1

I am working with cakephp 2.5 and trying to save a pdf file into root directory named Service_Invoices .

PDF File name is :

$pdf_file_name = 'ISE-00000104/17.pdf';

And the Root path :

$pdf_file_path = WWW_ROOT . 'files\Service_Invoices';

The problem is the slash in the file name. How to save this file with filename contain slash.

NB. The file name is a invoice id so it can not be changed.

  • 2
    Change the slash to something neutral, like a `-`. – Nigel Ren Sep 06 '17 at 10:59
  • 4
    don't use slashes in filenames – ArtOsi Sep 06 '17 at 11:00
  • 1
    presuming a linux server, you cant: https://stackoverflow.com/questions/9847288/is-it-possible-to-use-in-a-filename if the name is important then you can encode it so it can be retrived, eg with base_64, or save the name elsewhere, such as a database or textfile etc – Steve Sep 06 '17 at 11:03

1 Answers1

0

The content of $pdf_file_name is not a filename, but a file path. The filename is 17.pdf.

Several options here:

  • You can remove the slash and replace with another char, if you want to keep the original file path information.
  • You can create the folder ISE-00000104 within your target directory and save the 17.pdf in there to have the same structure.
  • You can remove the path information and just save 17.pdf to $pdf_file_path.

Filenames with a slash are not possible on Windows or Unix.

iquellis
  • 979
  • 1
  • 8
  • 26