My script uploads the selected pictures to a folder but in my other page I have to see it. But I can't see my uploaded picture.
But if I manually drag and drop the picture from the desktop to the folder then I can see the picture on the page.
This is my code where I want show the uploaded picture:
$image = "../images/accommodatie/".$row2['acco_id']."/";
$images = glob($image."*.jpg");
sort($images);
if (count($images) > 0) {
$img = $images[0];
$img = str_replace("../","", $img);
echo "<a href='acco.php'>
<div>
<div>
<img src='$img'>
</div>";
}
I checked a few times, The folder location is correct, so that can not be the problem.
You're missing and closing double quote and a semi colon after your echo :
if (count($images) > 0) {
$img = $images[0];
$img = str_replace("../","", $img);
echo "<a href='acco.php'>
<div>
<div>
<img src='$img'>
</div>"; //<----- SEMI COLON HERE
}
Related
I am trying to write a script that displays images and/or mp4 files. The image and mp4 file names are stroed in a data table.
When the script runs it needs to loop through the array returned by the mySQL statement. Each returned record has a column called "FileType" which contains either a 1 for an image file or 2 for an mp4 file.
My thinking is that as the do while loop is executed it looks at the content of "FileType" it is trapped by the if statement and uses the appropriate code to display the file. The issue I have is the script is only
displaing rows where the column "FileType" contains 1.
So if the first row contains an image file, it displays, but if the row contains an mp4 file it is not displayed.
Can anyone see where I have gone wrong and how I can fix it so it loops through the array of rows and displays each one.
My code:
do {
$FileType = $row_signage['FileType'];
if($row['DisplayType'] == "P" ) {
$DisplayWdith = "1080";
$DisplayHeight = "1920";
} else {
$DisplayWdith = "1920";
$DisplayHeight = "1080";
}
?>
<div>
<?php if($FileType == 1) { ?>
<img src="/<?=$ImagePath . $row_signage['SignageImageName']?>" class="responsive"/>
<?php } elseif($FileType == 2) { ?>
<div id="video_player">
<video width="<?php echo $DisplayWdith;?>" height="<?php echo $DisplayHeight;?>" autoplay muted playsinline>
<source src="/<?php echo $ImagePath.''.$row['SignageImageName'];?>"/>
</video>
<?php } ?>
</div>
} while ($row_signage = mysqli_fetch_array($fb)); ?>
Code rewrite and working:
<?php while($row = $fb->fetch_array()):
$FileType = $row['FileType'];
if($row['DisplayType'] == "P" ) {
$DisplayWdith = "1080";
$DisplayHeight = "1920";
} else {
$DisplayWdith = "1920";
$DisplayHeight = "1080";
}
?>
<div class="banner-container" data-delay-time="<?=$row['TimeLapse']?>">
<div>
<a>
<?php if($FileType == 1) { ?>
<img src="/<?=$ImagePath . $row['SignageImageName']?>" class="responsive"/>
<?php } else { ?>
<video id="video_player" width="<?php echo $DisplayWdith;?>" height="<?php echo $DisplayHeight;?>" autoplay muted playsinline>
<source src="/<?php echo $ImagePath.''.$row['SignageImageName'];?>"/>
</video>
<?php } ?>
</a>
</div>
</div>
<?php endwhile ?>
Good day everyone, so I have a code here for my site for uploading images to customer profile photos, but if they haven't uploaded yet it shows a broken image, how do I put a placeholder instead of a broken image.
<div class="panel-body">
<a data-target="#myModal" data-toggle="modal" href=
""><img class="img-hover" src="<?php echo web_root. "customer/".$res->CUSPHOTO; ?>"
style="width:100%; height:100%;text-align:center" title=
"profile image"></a>
</div>
This is my code for uploading the image
function doupdateimage(){
$errofile = $_FILES['photo']['error'];
$type = $_FILES['photo']['type'];
$temp = $_FILES['photo']['tmp_name'];
$myfile =$_FILES['photo']['name'];
$location="customer_image/".$myfile;
if ( $errofile > 0) {
message("No Image Selected!", "error");
redirect(web_root. "index.php?q=profile");
}else{
#$file=$_FILES['photo']['tmp_name'];
#$image= addslashes(file_get_contents($_FILES['photo']['tmp_name']));
#$image_name= addslashes($_FILES['photo']['name']);
#$image_size= getimagesize($_FILES['photo']['tmp_name']);
if ($image_size==FALSE ) {
message(web_root. "Uploaded file is not an image!", "error");
redirect(web_root. "index.php?q=profile");
}else{
//uploading the file
move_uploaded_file($temp,"customer_image/" . $myfile);
$customer = New Customer();
$customer->CUSPHOTO = $location;
$customer->update($_SESSION['CUSID']);
redirect(web_root. "index.php?q=profile");
Assuming that "basically has no value" means NULL you could check for that value:
<?php
if (is_null($res->CUSPHOTO)) {
$url = web_root. "customer/anonymous.jpg";
}
else {
$url = web_root. "customer/".$res->CUSPHOTO;
}
?>
<div class="panel-body">
<a data-target="#myModal" data-toggle="modal" href="">
<img class="img-hover"
src=<?php echo '"'.$url.'"' ?>
style="width:100%; height:100%;text-align:center"
title="profile image">
</a>
</div>
Here anonymous.jpg is the image to be displayed when no photo has been uploaded.
Opinion: Personally I don't like mixing the PHP tags into HTML like that. You never know exactly what will happen. I always write either HTML or PHP, not mixed, but I know it can be done. That's the reason I do the strange thing with the quotes around $url, I really don't like a PHP tag inside a HTML string.
How do I properly echo images combining HTML and PHP? $offer['picture'] has link saved as example.com/picture.png. I've tried many different options, but nothing works. Can anyone help me out?
foreach($json['offers'] as $offer) {
$image = $offer['picture'];
?>
<img src="<?php echo $image ?>">
<?php
}
If there is only example.com/picture.png in $offer['picture'], problem is that images linked incorrectly. You should add http:// before image link to make browser sure you are loading image by absolute path.
foreach($json['offers'] as $offer) {
$image = $offer['picture'];
?>
<img src="http://<?php echo $image ?>">
<?php
}
Well it depends on your directory structure.
suppose your images are in example.com/assets/images/photo-1.jpg
your code should be
<?php foreach($json['offers'] as $offer) {
$image = $offer['picture']; ?>
<img src="http://www.example.com/assets/images/<?php echo $image; ?>">
<?php } ?>
In fact, you need to concatenate or hard code the path and image name will be appended dynamically.
Try this syntax,
<?php
foreach($json['offers'] as $offer) {
$image = $offer['picture'];
echo "<img src='$image' />";
}
?>
I Have a problem while uploading image to my php page .. i tried this code and its worked and the image uploaded but i can't show it on the page ..
please help ^^
if ($_FILES["img"]["name"]) {
$name = $_FILES["img"]["name"];
$tmp_name = $_FILES['img']['tmp_name'];
$error = $_FILES['img']['error'];
if (!empty($name)) {
$location = '/var/www/html/1.jpg';
if (move_uploaded_file($tmp_name, $location.$name)){
echo 'Image Uploaded';
echo nl2br("\n");
echo nl2br("\n");
echo <<<HEREDOC
<div style="float:left;margin-right:10px">
<img src="{$location}" alt = "Ur Image" width="400" height="400"/>
</div>
HEREDOC;
}
}
else {
echo 'please choose a file';
}
}
I have a feeling that the issue is related to your $location variable. When you save the file, you save it to /var/www/html/1.jpg1.jpg since you do $location.$name, but when you try and display it, you only use the $location, which is /var/www/html/1.jpg.
Essentially, change:
<img src="{$location}" alt = "Ur Image" width="400" height="400"/>
to
<img src="{$location.$name}" alt = "Ur Image" width="400" height="400"/>
EDIT
And as meta pointed out, don't use /var/www/html/... in the image source. If /var/www/html is the root of the website where the PHP file lives, change yout $location variable to
$location = '/var/www/html/';
And change
<img src="{$location}" alt = "Ur Image" width="400" height="400"/>
to
<img src="{$name}" alt = "Ur Image" width="400" height="400"/>
Don't use physical location /var/www... in src, use URL instead (which would depend on your http server configuration). But you can try something like http://your.domain/1.jpg
or localhost/i.jpg or you could even try relative path src="/1.jpg" or src="html/1.jpg"
make sure the image is uploading where you think it is suppoed to go
if(isset($_POST['addImage'])){
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
$target_dir = "$myfolder/";
$target_file = $target_dir . basename($_FILES['userfile']['name']);
move_uploaded_file($_FILES['userfile']['tmp_name'], $target_file);
} else {
die('<br>An error occurred importing the file: '.$_FILES['userfile']['error']);
}
then show image with src='$target_file'
I have retrieved images from a folder and using fancybox plugin displayed all the images as picassa view.. only problem is how to bring all the retrieved images into one album. All the images are come one by one, because in while loop. I want all the images into a album. that is, if i have 4 images means, make all 4 into 'profilepic' album, here is my code..
PHP
//get all image files with a .jpg extension.
$images = glob($directory . "*.jpg");
//print each file name
foreach($images as $image)
{
echo $image;
?>
<a class="fancybox" rel="group" href="<?php echo $image; ?>"><img src="<?php echo $image; ?>" alt="" />
<?php
//echo "<a class='fancybox' rel='group' href='$image'><img src='$image' alt='' /></a>";
}
?>
SCRIPT
<script type="text/javascript">
$(document).ready(function() {
$(".fancybox").fancybox();
});
</script>