I wanted to know how to download a file php
, I produced a cycle while
to go through and give the corresponding path, create a folder called "uploads" to upload the address, for example: ../uploads/ to upload my files, I tried the following code:
<a href="#" download="<?php echo $row["RUTA"] ?>">
It makes me download a pdf file but it is unusable, I don't know if this is the correct way, I will appreciate the help! Thank you!
(EDITED)
if (isset($_FILES["file"]) && !empty($_FILES["file"]["name"])) {
$archivoExist = $_FILES["file"]["name"]; //Variable que almacena el archivo ,su nombre
$directorio = "../DIR/"; //Directorio de carpeta subidas donde se subiran los archivos
$archivo = $directorio . basename($_FILES["file"]["name"]); //Archivo principal donde se sube
$tipoArhivo = strtolower(pathinfo($archivo, PATHINFO_EXTENSION));
if (!file_exists($archivo)) { //Si no existe el archivo entonces se p
if ($tipoArhivo == "pdf" || $tipoArhivo == "jpg" || $tipoArhivo == "png") {
if (move_uploaded_file($_FILES["file"]["tmp_name"], $archivo)) {
//Validaciones e insercion
}
}
}
}
Here you can see how I get the sent file.
The url of the file to download must go in the href attribute, in the download attribute the name you want to give to the downloaded file must go, you must also change the double quotes for single quotes in
$row["RUTA"]
, you should get a result similar to this:<a href="<?php echo $row['RUTA'] ?>" download="NOMBRE_DEL_ARCHIVO">