0

I downloaded a PHP File-manager called 'FileThingie' in which you can upload files to your directories. It works fine, but when I try to upload a new file whose path is very large (many characters) PHP gives me an error.

The error that PHP displays is:

Warning: move_uploaded_file(../../archivos/admin_arch/2019/365 GRADOS EMPRESA NUMERO 1/01. ENERO/OPERACIONES/GRANDES DESARROLLOS/MI EMPRESA GENERICA SA DE CV/GENERALES/Prueba/CUMA_VH1_SED_SEM33_1.pdf) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\Project\Sistema\admin_arch\index.php on line 822


Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\Windows\Temp\phpE1F.tmp' to '../../archivos/admin_arch/2019/365 GRADOS EMPRESA NUMERO 1/01. ENERO/OPERACIONES/GRANDES DESARROLLOS/MI EMPRESA GENERICA SA DE CV/GENERALES/Prueba/CUMA_VH1_SED_SEM33_1.pdf' in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\Project\Sistema\admin_arch\index.php on line 822

Code:

if (@move_uploaded_file($c['tmp_name'], $ruta_archivo_final )) {
    @chmod(ft_get_dir() . "/{$c['name']}", 0777);
    $msglist++;
    ft_set_message("Archivo subido correctamente. Nombre: " . $nomenclatura_temp);
    ft_invoke_hook('upload', ft_get_dir(), $c['name']);
}                  
                                } 

As I told you, it works fine if the pathname is not that big (there seems to be a limit), so I do not think there is an issue with permissions.

Thanks in advance!

phseo
  • 1
  • 1
  • There is a max length of paths, which is about 255 (or 260?). It's a limitation on the operating system, not with PHP. – Qirel Jul 16 '19 at 07:19
  • Let us be clear: This is a limitation of Windows. I think it is 259 characters. See: https://stackoverflow.com/q/265769/3986005 You have to look at the path when you write out the `../../` bit as well. There seems to be an option in Windows to undo this limit. – KIKO Software Jul 16 '19 at 07:21

1 Answers1

0

I had this all the time when working with node (javascript) on windows.

It is a windows problem, PHP is completely fine with long filenames.

from: https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file

Maximum Path Length Limitation

In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters.

And the fix (I haven't tried it yet):

https://www.howtogeek.com/266621/how-to-make-windows-10-accept-file-paths-over-260-characters/

Erwin Moller
  • 2,375
  • 14
  • 22