I have this code
<html>
<body background="http://newevolutiondesigns.com/images/freebies/abstract-background-22.jpg">
<br><br><br><br><br>
<DIV align="center">
<?php
$img = $_GET["img"];
?>
<?php
if($img=="") { echo ""; } else { echo "<img src='" . $img . "' />"; } ?>
<br>
</body></html>
I'm using this for screensnapr so when i'm trying to see the picture with http://imagesnappper.co.cc/Images?img= it autoamtically adds a / after ?img=
so it's like http://imagesnappper.co.cc/Images?img=/8kd6lx.jpg and it won't show the image how to delete that slash?
Try using...
$img = ltrim($img, "/");
There are a number of ways, but the simplest and nastiest that comes to mind is substr():
$img=substr($_GET[img], 1);
Related
I would like to display an image using PHP. Here is what I have tried, but it does not work.
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
</head>
<body>
<div class="container">
<?php
$img_name = echo $row['img_name']; //I get it from the database
img_block($img_name); //Display the image here.
//Function to display image
function img_block(img_src) {
// e.g. img_src = cat.jpg;
$img_input = "images/" . img_src;
$set_img = '<img class="media-object-ph" src="'.$img_input.'" width="380" height="290" alt="...">';
return $set_img;
}
?>
</div>
</body>
</html>
Thank you in advance.
Too long for a comment... You have a number of errors:
$img_name = echo $row['img_name'];
should be:
$img_name = $row['img_name'];
You are calling your function but not doing anything with the return value, you need to echo it:
img_block($img_name);
should be:
echo img_block($img_name);
Finally you have not put the required $ on the img_src variable in your function; it's definition should be:
function img_block($img_src) {
// e.g. img_src = cat.jpg;
$img_input = "images/" . $img_src;
$set_img = '<img class="media-object-ph" src="'.$img_input.'" width="380" height="290" alt="...">';
return $set_img;
}
If you make all these changes, and (e.g.) $row['img_name'] = 'image1.jpg', your code will output:
<img class="media-object-ph" src="images/image1.jpg" width="380" height="290" alt="...">
Demo on 3v4l.org
Can't get image URL to display in my code; this is my URL: https://production.cdmycdn.com/webpack/renderer/d7285ffbbd0ca6d1d2179f7d22ea1f67.svg
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
<!DOCTYPE html>
<html>
<head>
<title>PHP Exercise 1: Links and Variables</title>
</head>
<body>
<h1>PHP Exercise 1: Links and Variables</h1>
<p>Use PHP echo and variables to output the
following link information:</p>
<hr>
<?php
$linkName ='<h1> Codecademy <h1>';
$linkURL = 'codecademy';
$linkImage =
'https://production.cdmycdn.com/webpack/renderer/d7285ffbbd0ca6d1d2179f7d22ea1f67.svg';
$linkDescription = 'Learn to code interactively, for free.';
$my_name = "peter";
echo "<img>" . $linkImage . "</img>";
echo $linkName;
echo "<br>";
echo $linkURL;
echo "<br>";
echo $linkImage;
echo "<br>";
echo $linkDescription;
$linkImage = 'https://production.cdmycdn.com/webpack/renderer/d7285ffbbd0ca6d1d2179f7d22ea1f67.svg';
echo '<img src="data:image/jpeg;base64,">';
?>
</body>
</html>
A link to an image should always be put in the src attribute when you're using the img tag in html.
That means you should be looking for something like "<img src=".$linkImage."></img>" instead of "<img>".$linkImage."</img>"
Of course, that only applies if the problem you're referring to is the fact that there should be an image after the sentence "Learn to code interactively, for free."
Works just fine for me. Try checking php permissions.
This question already has an answer here:
upload image to mysql database php
(1 answer)
Closed 9 years ago.
this is code of the page that I will get the image from(work perfectly)
<?php
ob_start();
session_start();
include('connect.php');
$id = $_GET['id'];
$query = mysql_query("SELECT * FROM news WHERE id=$id");
$row = mysql_fetch_assoc($query);
header("Content-type: image/jpeg");
echo $row['image'];
?>
and this is my page that i get the image to in
<?php
ob_start();
session_start();
include('includes/connect.php');
include('includes/phpCodes.php');
$id = $_GET['id'];
function showNews() {
$data = array( 'id' => $id );
$base = "includes/getImage.php";
$url = $base. "?" . "id=36";
echo $url;
echo '<img src=includes/getImage.php class="newsImage">';
echo '<h1><p class="subjecTitle">هنا العنوان</p></h1>
<div class="newsContent">
hihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihi
</div>
';
}
?>
<!DOCTYPE html>
<html>
<head>
<title>عينٌ على الحقيقة</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/mainstyle.css">
<link rel="stylesheet" type="text/css" href="css/showstyle.css">
<script lang="javascript">
function logout( myFrame ) {
myFram.submit();
}
</script>
</head>
<body>
<div class="wrapper">
<?php headerCode(); ?>
<div class="content" dir="rtl">
<?php showNews(); ?>
</div>
</div>
</body>
</html>
i think my wrong is in , can someone tell me how can I solve it?, sorry for my bad english
Cleared it up for you:
echo '<img src="includes/getImage.php?id=' . $id . '" class="newsImage">';
Should 100% work (if the $id param has a value of course).
Update to fix the missing $id var:
<?php
ob_start();
session_start();
include('includes/connect.php');
include('includes/phpCodes.php');
$id = $_GET['id'];
function showNews(){
$id = $_GET['id'];
$base = "includes/getImage.php";
$url = $base. "?" . "id=36";
echo $url;
echo '<img src="includes/getImage.php?id=' . $id . '" class="newsImage">';
echo '
<h1><p class="subjecTitle">??? ???????</p></h1>
<div class="newsContent"></div>
';
}
?>
why are you using two different pages?
put both code in single page and simply do this
<img src=includes/<?php echo $row['image']; ?> class="newsImage">
Change :
echo ' <img src=includes/getImage.php class="newsImage">';
To :
echo ' <img src="includes/getImage.php?id='.$id.'" class="newsImage">';
Please note src has " and also make sure that includes/getImage.php return a image path
Hey iam making a slot machine and is almost done. The only thing i need is the credit's to stay so it just add points on the credit's. Like if i have 100 credits and then get 25 credits i want it to say 125 credits. Now i don't know how to get the credits from the round before.
This is what i got:
<?
$tal = rand (1,3 ); {
echo "<img src='css/billeder/enarmet$tal.gif' class=billed />";
$tal2 = rand (1,3 );
echo "<img src='css/billeder/enarmet$tal2.gif' class=billed />";
$tal3 = rand (1,3 );
echo "<img src='css/billeder/enarmet$tal3.gif' class=billed />"; }
?>
</div>
<div id="credits">
<h3 id="credits2">CREDITS</h3>
<h3 id="credits3"><?php
$credits=$_GET['credits'];
if ($tal . $tal2 . $tal3 == 111){
($credits=($credits+100));
}
if ($tal . $tal2 . $tal3 == 222){
($credits=($credits+50));
}
if ($tal . $tal2 . $tal3 == 333){
($credits=($credits+25));
}
echo $credits;
?></h3>
</div>
</div>
<form action="index.php" method="POST">
<input type="submit" value="SPIN" class="knap">
</form>
<form action="cashout.php" method="POST">
<input type="submit" value="CASH OUT" class="knap">
</form>
</div>
What about using sessions? Store and retrieve credits from session storage using
session_start();
$credits = $_SESSION['credits'];
at the top of your script and
$_SESSION['credits'] = $credits;
at the bottom.
This way credits will be preserved between page-loads.
You can remove the curly braces at the end of the following lines, its not need and try it.
<?
$tal = rand (1,3 ); { // remove the open brace
echo "<img src='css/billeder/enarmet$tal.gif' class=billed />";
...
echo "<img src='css/billeder/enarmet$tal3.gif' class=billed />"; } // remove the close brace
?>
I have the following code that sets a background if user has uploaded to database. If user has NOT uploaded an image then the result is a blank img src=''
I need to set this as an if isset function so I can plug in an alternate image if user has not uploaded anything.
Here is the current code:
<div id="background"><?php echo isset($background_image) && file_exists(ROOT.$background_image)?"<img src='$background_image' alt='' />":'';?></div>
Your code's a little dirty, opening php and closing it mid-html tag is only going to make it confusing for you in the future.
You're echoing back an isset which is just echo'ing back a boolean.
Try this;
$background_image = ""; // Not sure what you're using here - their username? Dump it in here anyway.
if (file_exists($background_image))
{
echo " <div id=\"background\">
<img src=\"{$background_image}\" alt=\"\" title=\"\" />
</div>";
}
Hope this helps.
Eoghan
I'm not sure what you mean, but a another aproach to what you are trying to do would be:
<div id="background">
<?php
$optionalImage = 'background.png';
$userImage = getUserImage();
if(empty($userImage)) {
$userImage = $optionalImage;
}
?>
<img src="<?php echo $userImage; ?>" />
</div>
Is it really neccessary to set the blank source of the image?
But a understandable and corrected code of what you are attempting is this
<div id="background">
<?php
echo "<img src='";
echo isset($background_image) && file_exists(ROOT.$background_image) ? $background_image : '';
echo "' alt='' />";
?>
</div>
The problem was that, either you were echo entire <img> tag, or just display ' '(Blank) with attached endings.
The short form:
echo "<img src='".(isset($background_image) && file_exists(ROOT.$background_image) ? $background_image : '')."' alt='' />";