Hi, I tried this code:

<?php
session_start();
$id=$_GET['fileid'];
if($id=="1")
{
	$dwnld = "File1.zip";  
}
else if($id=="2")
{
	$dwnld = "File2.zip";
}
else if($id=="3")
{
	$dwnld= "File3.zip";  
}
if($id)
{
	header("Content-type: application/download"); 
	header("Content-disposition: filename=$dwnld");
	readfile($dwnld);
}
?>

I want the user to download those files from a folder named Archives... Example:
Archives/File1.zip
or Archives/File2.zip
Please I want your help quickly... Thanks.

Recommended Answers

All 18 Replies

Maybe you did not understand.. explain? ::)
I just want to download a file by clicking on a button.. can any one help me? :? :-/

Member Avatar for fatihpiristine

<a href="file1">File 1</a>
<a href="file2">File 2</a>
.....
.....
put this in for loop and it is ready

<a href="file1">File 1</a>
<a href="file2">File 2</a>
.....
.....
put this in for loop and it is ready

maybe you did not ubderstand...
I want the page download the file automatically when the variable ($id=="1") or ($id=="2")
or ($id=="3")....
can anyone tell me? Please quickly... Thanks.

Member Avatar for fatihpiristine

i think u dont know how to make request. it was an idea. just put there if else looop.. thats all

i think u dont know how to make request. it was an idea. just put there if else looop.. thats all

Thanks but that is not correct.
I want a button locates to another page which can download a file automaticially in the header.
:-/
Thanks..

Member Avatar for fatihpiristine

well.. i ll try to find my code then lll post it

Thanks... Waiting for it... :)

Intenta con eso a ver si te funciona.. :p

<?php
session_start();
$id=$_GET['fileid'];
if($id=="1")
{
    $dwnld = "File1.zip";  
}
else if($id=="2")
{
    $dwnld = "File2.zip";
}
else if($id=="3")
{
    $dwnld= "File3.zip";  
}
if($id)
{
        header("Content-type: application/octet-stream");
        header("Content-Disposition: attachment; filename=".$dwnld."\n\n");
        $fp=fopen("$dwnld", "r");
       fpassthru($fp);
}
?>

I want the user to download those files from a folder named Archives... Example:
Archives/File1.zip
or Archives/File2.zip
Please I want your help quickly... Thanks.

Intenta con eso a ver si te funciona.. :p

<?php
session_start();
$id=$_GET['fileid'];
if($id=="1")
{
    $dwnld = "File1.zip";  
}
else if($id=="2")
{
    $dwnld = "File2.zip";
}
else if($id=="3")
{
    $dwnld= "File3.zip";  
}
if($id)
{
        header("Content-type: application/octet-stream");
        header("Content-Disposition: attachment; filename=".$dwnld."\n\n");
        $fp=fopen("$dwnld", "r");
       fpassthru($fp);
}
?>

I want the user to download those files from a folder named Archives... Example:
Archives/File1.zip
or Archives/File2.zip
Please I want your help quickly... Thanks.

Thanks, But what will these functions do :

   $fp=fopen("$dwnld", "r");
   fpassthru($fp);

Thanks, But what will these functions do :
$fp=fopen("$dwnld", "r");
fpassthru($fp);

Mira, se supone que quieres bajar un archivo en estes vaso .zip, entonces este script lo debes de poner en la carpeta donde estan los archivos o concatenarle la ruta.
Ahora, lo que hace esta linea $fp=fopen("$dwnld", "r"); supongo que ya sabes, pero bueno crea un descriptor de archivo llamado fp ($fp), abre el archivo que se encuentre el nombre en $dwnld como solo lectira, lo que hace el fpassthru($fp); es leer todo lo que tenga el archivo y cuando llega al final de archivo lo cierra.. es lo que hace.. pero utiliza te pido que lo pruebes... lo que hace es bajar en este caso el archivo .zip que le pases en la variable $dwnld.

Hay otra opcion para esto pero si el usuario tiene instalos los plugins para poder abrir los archivos los visualizara en el browser, pero esto no seria automatico.. tendrias ke dar clic..

<A href="ruta/archivo" >texto</A>

no se si se pueda jamas lo he probado ya que son nuevo en php pero no se si puedas hacerlo asi..

header('location: http://127.0.0.1/archivos/'.$dwld);

fin repito no lo he calado.. pero podrias intentarlo.. espero y te ayude con eso.. :p

Thanks, But what will these functions do :

$fp=fopen("$dwnld", "r");
fpassthru($fp);[/quote]

Mira, se supone que quieres bajar un archivo en estes vaso .zip, entonces este script lo debes de poner en la carpeta donde estan los archivos o concatenarle la ruta.
Ahora, lo que hace esta linea $fp=fopen("$dwnld", "r"); supongo que ya sabes, pero bueno crea un descriptor de archivo llamado fp ($fp), abre el archivo que se encuentre el nombre en $dwnld como solo lectira, lo que hace el fpassthru($fp); es leer todo lo que tenga el archivo y cuando llega al final de archivo lo cierra.. es lo que hace.. pero utiliza te pido que lo pruebes... lo que hace es bajar en este caso el archivo .zip que le pases en la variable $dwnld.

Hay otra opcion para esto pero si el usuario tiene instalos los plugins para poder abrir los archivos los visualizara en el browser, pero esto no seria automatico.. tendrias ke dar clic..

<A href="ruta/archivo" >texto</A>

no se si se pueda jamas lo he probado ya que son nuevo en php pero no se si puedas hacerlo asi..

header('location: http://127.0.0.1/archivos/'.$dwld);

fin repito no lo he calado.. pero podrias intentarlo.. espero y te ayude con eso.. :p

jeje.. disculpa lo puese dos veces.. :s

jeje.. disculpa lo puese dos veces.. :s

:( Sorry but I do not know a lot in France, Please speak in English.
Maybe you did not understand my question, Please read it again.
I want the page downloads a file automatically(The file is in a sub-folder)(Example: www.domain.com/Archive/File1.zip

:( Sorry but I do not know a lot in France, Please speak in English.
Maybe you did not understand my question, Please read it again.
I want the page downloads a file automatically(The file is in a sub-folder)(Example: www.domain.com/Archive/File1.zip

If you did not understand the question please say that to explain more, or to talk in private
:-/
Thanks.

Yes, I yes understand, I speak Spanish not France, my English not is good, i do is put a link, on link send the name of file, and before only do
$f=$_GET["arc"];
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=".$f."\n\n");
$fp=fopen("$desca", "r");
fpassthru($fp);


ok ok ok.. alrady mira solo pon

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=".$dwnl."\n\n");
$fp=fopen("$desca", "r");
fpassthru($fp);


en el otro codigo me equivoque.. en esta parte
$fp=fopen("$desca", "r");

solo pon eso la variable $desca no tiene nada.. y solo te lo descarga.. te digo porke me funciona.. bueno sale el cuadro de dialogo.. o no quieres que salga el cuadro de dialogo..?

<?php
session_start();
$id=$_GET['fileid'];
if($id=="1")
{
$dwnld = "File1.zip";
}
else if($id=="2")
{
$dwnld = "File2.zip";
}
else if($id=="3")
{
$dwnld= "File3.zip";
}
if($id)
{
 header("Content-type: application/octet-stream"); //to specify the content-type of the file. 
header("Content-Disposition: attachment; filename=".$dwnld."\n\n"); //to 'generate' that file save dialog box
echo $dwnld; // writing the contents to that file.
}
?>

I hope it helps.

Thank you, Please read the text again,
I want to download a file from a sub folder.
Can you help me ? :-/

Thank you, Please read the text again,
I want to download a file from a sub folder.

Which sub folder ? You can concat the path of the sub folder like $dwnld = "path/of/the/subfolder/here/File1.zip";

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.