Hello, I have a question and it is that I have a form to be able to upload documents to my server (their extension does not matter), so the files stored there have different extensions: jpge, jpg, png, pdf... etc.
What I want is that it recognizes the extension automatically to be able to download/view whatever type of file it is
I need to know why the extension of the file stored on my server is not recognized with the following code.
<?php
// la variable albarán normalmente es una serie de numeros. ej: 51484
$albaran = $row['albaran']; //Me traigo el nombre del archivo
$tipo_archivo = file_get_contents("albaranes/" . $albaran); // albaranes/ es la carpeta
$tipo_archivo = explode("/", $tipo_archivo);
$tipo_archivo= '.' . $tipo_archivo[1];
$nombre_archivo= $albaran . $tipo_archivo;
?>
<?php if ($row['albaran'] != ""): ?>
<a href="albaranes/<?php echo $nombre_archivo; ?>">Ver albarán Nº <?php echo $nombre_archivo; ?></a>
<?php endif; ?>
Well, what you're looking for is simple, but we may need to add some control. Let's go with the code first:
With this we generate the link you want, but now, what happens if there are two documents with the same name? I understand that you have that under control. If so, with this small code it will serve you.
Cheers,