0
I need the code to check if this parameter with the image exists, if it exists, I have to display it on the screen. How can I do?
Note: The parameter with the image should be passed by the user in the url. That is, with GET.
0
I need the code to check if this parameter with the image exists, if it exists, I have to display it on the screen. How can I do?
Note: The parameter with the image should be passed by the user in the url. That is, with GET.
6
if (isset($_REQUEST['url_da_imagem']))
{
echo '<img src="'.$_REQUEST['url_da_imagem'].'">';
}
In place of $_REQUEST
you can use $_GET
, is that $_REQUEST
works for both GET and POST, so if you need it you can receive the URL by POST as well, without having to change your code.
Edit:
Ah, the URL would look like this: http://seudomain.com?url_da_imagem=http://dominiodaimagem.com/imagem.jpg
And to see if $_GET exists? I’m trying to use : <?php if(isset($_GET['image'])) { echo 'existe'; }Else ː echo 'does not exist; } ? > But the site breaks...
Define me better as "break". And whenever you post code, use markups to make it easier to read. Place the piece of code in the middle of the text.
The screen turns white, and taking the if back to work
I edited the answer with a verification code ready, but if you prefer to change to $_GET
, do not forget to change as much in condition as in block.
Thanks brother, thank you very much!
3
I imagine Curl can help.
$foto = $_GET['imagem_url'];
$ch = curl_init($foto);
curl_exec($ch);
$HTTPCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($HTTPCode == '200'){
echo '<img src=".'$foto.'">';
}
else
echo 'Imagem não encontrada';
Browser other questions tagged php get
You are not signed in. Login or sign up in order to post.
possible duplicate of How to check if an image exists in a remote URL?
– Jorge B.
@Jorgeb.Actually this does not answer my question, my question is different.
– GWER
Oh I misunderstood the question. When you talk about passing this parameter with the image you mean with the right image link?
– Jorge B.