Forzar Descarga Ficheros en PHP

Una de los problemas más habituales que nos encontramos es el poder forzar la descarga de un determinado fichero desde el navegador del cliente, evitando así que lo abra.

Para ello podemos usar la siguiente función en PHP.

function force_download($file)
{
    if ((isset($file))&&(file_exists($file))) {
       header("Content-length: ".filesize($file));
       header('Content-Type: application/octet-stream');
       header('Content-Disposition: attachment; filename="' . $file . '"');
       readfile("$file");
    } else {
       echo "No hay un fichero seleccionado";
    }
}

 

162 responses to “Forzar Descarga Ficheros en PHP

  1. jordan 1 off white

    I am often to running a blog and i really appreciate your content. The article has actually peaks my interest. I am going to bookmark your website and preserve checking for brand spanking new information.

  2. paul george shoes

    An fascinating discussion is price comment. I feel that it is best to write more on this subject, it won’t be a taboo topic but typically people are not enough to talk on such topics. To the next. Cheers

  3. jordan sneakers

    Oh my goodness! a tremendous article dude. Thanks Nonetheless I am experiencing subject with ur rss . Don抰 know why Unable to subscribe to it. Is there anybody getting identical rss drawback? Anybody who knows kindly respond. Thnkx

  4. supreme new york

    Aw, this was a really nice post. In thought I would like to put in writing like this additionally ?taking time and actual effort to make a very good article?but what can I say?I procrastinate alot and certainly not appear to get one thing done.

  5. golden goose

    There are some attention-grabbing deadlines in this article however I don抰 know if I see all of them heart to heart. There’s some validity however I will take maintain opinion until I look into it further. Good article , thanks and we want extra! Added to FeedBurner as nicely

  6. supreme

    I抦 impressed, I must say. Actually hardly ever do I encounter a blog that抯 each educative and entertaining, and let me let you know, you may have hit the nail on the head. Your thought is outstanding; the problem is something that not sufficient people are speaking intelligently about. I’m very completely satisfied that I stumbled across this in my search for something regarding this.

  7. off white shoes

    Aw, this was a very nice post. In concept I would like to put in writing like this moreover ?taking time and precise effort to make a very good article?but what can I say?I procrastinate alot and by no means seem to get something done.

  8. kyrie 4

    I am usually to running a blog and i really admire your content. The article has really peaks my interest. I’m going to bookmark your site and hold checking for new information.

  9. supreme clothing

    After research a couple of of the blog posts on your website now, and I really like your means of blogging. I bookmarked it to my bookmark website list and shall be checking back soon. Pls try my web site as effectively and let me know what you think.

  10. jordan 12

    I抎 should verify with you here. Which is not one thing I often do! I enjoy reading a submit that can make folks think. Also, thanks for allowing me to comment!

  11. steph curry shoes

    After research a few of the blog posts on your web site now, and I really like your way of blogging. I bookmarked it to my bookmark website list and shall be checking again soon. Pls take a look at my web site as well and let me know what you think.

  12. moncler

    The following time I learn a blog, I hope that it doesnt disappoint me as a lot as this one. I mean, I know it was my option to learn, however I truly thought youd have one thing fascinating to say. All I hear is a bunch of whining about something that you would repair if you happen to werent too busy in search of attention.

  13. adidas yeezy

    An interesting discussion is worth comment. I believe that you need to write more on this subject, it might not be a taboo subject however generally people are not sufficient to speak on such topics. To the next. Cheers

  14. yeezy

    The next time I learn a weblog, I hope that it doesnt disappoint me as much as this one. I mean, I know it was my option to read, however I actually thought youd have one thing fascinating to say. All I hear is a bunch of whining about one thing that you could repair should you werent too busy in search of attention.

Deja una respuesta

Tu dirección de correo electrónico no será publicada.

Rúa Pilar Miró n 6 Santiago de Compostela

Jersey St , Manchester, Greater Manchester M4 6JG, GB

T. 609 538 171 - 634 59 34 43

info@teslatechnologies.com