Jump to content

Download imagens


JPedro.CdT

Recommended Posts

um ficheiro php que obtenha o id da imagem pelo get, num <a> link, do tipo:

<a href="http://localhost/download.php?id=1">Download</a>

tedo esse ficheiro php que va buscar a imagem pelo id e insira as tais headers para forçar o output em download (octet/stream acho que é esse o mime Type)

B2R » Beat2Revolution v3.0b | Regista e divulga-nos

beat2revolution.net
Link to comment
Share on other sites

<a href="/path/to/image" download="myimage"><img src="/path/to/image" /></a>

Vê se isso serve

este código apenas funciona no google chrome.

<a href="/path/to/image" download="myimage"><img src="/path/to/image" /></a>

Edited by I-NOZex

B2R » Beat2Revolution v3.0b | Regista e divulga-nos

beat2revolution.net
Link to comment
Share on other sites

porque nao mudas as permissoes da pasta?

ou

porque que nao mandas uma header em php para o browser fazer download?

Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender.

A beleza de um código está em decompor problemas complexos em pequenos blocos simples.

"learn how to do it manually first, then use the wizzy tool to save time."

"Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."

Link to comment
Share on other sites

porque nao mudas as permissoes da pasta?

ou

porque que nao mandas uma header em php para o browser fazer download?

Apache solution with mod_headers

Place your downloadable images in a directory. Inside this directory, create a .htaccess file with the following contents:

SetEnvIf Request_URI "([^/]+\.jpg)$" REQUESTED_IMAGE_BASENAME=$1
SetEnvIf Request_URI "([^/]+\.png)$" REQUESTED_IMAGE_BASENAME=$1
Header set Content-Disposition "attachment; filename=\"%{REQUESTED_IMAGE_BASENAME}e\"" env=REQUESTED_IMAGE_BASENAME

fonte: stackoverflow

B2R » Beat2Revolution v3.0b | Regista e divulga-nos

beat2revolution.net
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.