yii2 display image not found error - yii2

i've got a problem with displaying image I've just uploaded by imagine.
Now in my view file I have
<?= Html::img("#uploads/$file->hash/$file->hash-$typeThumbnail.$file->extension") ?>
which correctly displays in browser
<img src="/home/user/projects/project/_protected/runtime/uploads/1d30a595950237c599deb4fe02750489/1d30a595950237c599deb4fe02750489-2.jpg" alt="">
This file exists in this directory. Also I've made 777 permission to each folder and file in project folder but still I receive 404 not found error...
What am I doing wrong?

try use code, like this.
$img = yii\helpers\Url::to('#web/uploads/').$file->hash.'/'.$file->hash-$typeThumbnail.$file->extension;
$image = '<img src="'.$img.'" width="600" />';
<img src="<?= Yii::$app->request->baseUrl . '/backend/web/uploads/' . $file->hash.'/'.$file->hash-$typeThumbnail.$file->extension ?>" class=" img-responsive" >

Related

how do I display an image saved in the db as a longblob?

I've stored a blob image in the database but I can't see it. I wrote this code
$queryi = "SELECT Foto FROM bhk WHERE Cod_Bhk = '".$Codice."' INTO DUMPFILE 'immagine.jpg'";
$resulti = mysqli_query($connessione_al_server,$queryi);
html code:
<img id="imgcaricata" class="mySlides" src="immagine.jpg" style="height:600px; width:auto;max-width:500px;">
This is valid if your blob has the mime type jpeg
echo '<img id="imgcaricata" class="mySlides"
src="data:image/jpeg;base64,'.base64_encode( $resulti["Foto"] ).'"
style="height:600px; width:auto;max-width:500px;" />';
Or try it with a separate php script like https://stackoverflow.com/a/7793098/5193536
<img src="data:image/jpeg;base64,<?php echo base64_encode( $resulti["Foto"] ); ?>" id="imgcaricata" class="mySlides" style="height:600px; width:auto;max-width:500px;"/>

Upload Frontend Image Wordpress

I have this code to upload an image from Edit Profile page and display it on Profil page:
Code on Edit Profile Page to upload image:
echo '<input type="file" name="my_file_upload" id="my_file_upload_id" class="bg_checkbox"/>';
function register_team_show_case_setting() {
//register our settings
register_setting('my_team_show_case_setting', 'my_file_upload');
}
require_once( ABSPATH . 'wp-admin/includes/image.php' );
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once( ABSPATH . 'wp-admin/includes/media.php' );
$attach_id = media_handle_upload('my_file_upload', $post_id);
if (is_numeric($attach_id)) {
update_option('option_image', $attach_id);
update_post_meta($post_id, '_my_file_upload', $attach_id);
}
Code to display image on Profile Page to display uploaded image:
echo wp_get_attachment_url(get_option('option_image'));
The upload part works, but when I go to the Profile Page to view the uploaded photo, it shows a URL instead of the image itself, like this: https://i.imgur.com/CSFFK1g.png
Should I make something like this to display correctly?
<img href="wp_get_attachment_url(get_option('option_image'));"/>
<img src="<?php echo wp_get_attachment_url(get_option('option_image')); ?>" />
You need to pass he image source to the src attribute not the href attribute, which is meant to send users to a different web page not render images.

PHP adding a class to an image url

This is the first time I am doing something using PHP. It might be a very stupid question but I want to add a class to this line:
<?php
$image_url='http://test.haardenenkachels.com/wp-content/uploads/s2dlogo.jpg';
?>
<img src="<?php echo $image_url;?>">
How do I add a class to this line?
Thank you so much!
Regards,
Jelle
<?php
$image_url='http://test.haardenenkachels.com/wp-content/uploads/s2dlogo.jpg';
$image_class='yourclass';
?>
<img class="<?php echo $image_class;?>" src="<?php echo $image_url;?>">
would give you
<img class="yourclass" src="http://test.haardenenkachels.com/wp-content/uploads/s2dlogo.jpg">
Remember, that you must add the class to your style sheet ... and of course you can find listed in the file where the tag is present img

How can I speed up the rendering of an image on my page?

I am creating a site where the user can post their advertisement and the user can upload a photo... I am posting the four latest ads pics in the top of my site... so everytime I navigate through my site those latest 4 ads pics will be displayed but the problem is it renders too long.. makes my site slowdown...
how can I optimize it? I need advice guys..
and btw, I'm saving those images in my database as blob.. and selecting the 4 latest ads in my database.
<?php if($latest_upload_count > 0){ ?>
<div class = "collapse navbar-collapse">
<div class = "container">
<div class = "row">
<?php while($get_lastest_pics = mysql_fetch_assoc($get_5_latest_ads_query_string_execute)){ ?>
<div class = "col-xs-3">
<img img src="data:image/jpeg;base64,<?php echo base64_encode($get_lastest_pics['img']); ?>" style = "height: 180px; width: 270px;" class="img-responsive img-thumbnail" alt="Cinque Terre" >
</div>
<?php } ?>
</div>
</div>
<br />
</div>
<?php } ?>
I tried omitting that and my site runs faster...
Save your images as files and only save paths to them in the database. Then generate thumbnails of smaller size to display them on the homepage (e.g. with ability to zoom-in those images by clicking on them) or just scale-down and optimize those images. You can save paths to thumbnails in the database too, or you can generate them on-fly (using some prefixes/subfixes in file names for different sizes).
Use some of well-known PHP libraries for images manipulations (like Imagick, Intervention Image or similar).
How about your code it self :
How about you write it like this :
if($latest_upload_count > 0){
echo "<div class = 'collapse navbar-collapse'><div class = 'container'><div class = 'row'>";
while($get_lastest_pics = mysql_fetch_assoc($get_5_latest_ads_query_string_execute)){
echo "<div class = 'col-xs-3'>
<img img src='data:image/jpeg;base64,".base64_encode($get_lastest_pics['img'])."' style = 'height: 180px; width: 270px;' class='img-responsive img-thumbnail' alt='Cinque Terre' >
</div>";
}
echo "</div></div><br /></div>";
}

html image not appearing

I have the following line of code:
<IMG SRC= "Home.png">
I copied this directly from a different part of my code that worked. However, now the home image won't show up on my site. It says it prints it, but it's not visible. What's going on?
edit:
if(isset($_SESSION['userInfo']['username'])){
echo '<div class = "header"><IMG SRC= "Home.png" ALT="image">
<IMG SRC= "ViewProfile.png" ALT="image"> <IMG SRC= "ViewCart.png" ALT="image">';
echo '</div>';
else{
echo '<div class = "header">
<IMG SRC= "Home.png">
<IMG SRC= "FAQ.png"></div>';
}
You are missing the closing parenthesis } for the if statement. That might be the problem.
Try this...
if(isset($_SESSION['userInfo']['username'])){
echo '<div class = "header"><IMG SRC= "Home.png" ALT="image">
<IMG SRC= "ViewProfile.png" ALT="image"> <IMG SRC= "ViewCart.png" ALT="image">';
echo '</div>';
} else {
echo '<div class = "header">
<IMG SRC= "Home.png">
<IMG SRC= "FAQ.png"></div>';
}
Try
<div class="header">
<img src="Home.png"/>
<img src="FAQ.png"/>
</div>
Is it a broken image icon on the browser?
One thing might be that Home.png is in another directory. Did you copy this code from the same file or another file (possibly located in another directory)? If you copied this code from a file located in another directory you will need to format the image source link accordingly.
For example say you have a directory structure like so:
-index.htm (File)
-Home.png (File)
-js (Directory)
-css (Directory)
-pages (Directory)
---example.htm (File inside Pages directory)
If you then copied the code from your index.htm file to the example.htm located in your pages directory you would need to modify the link in the example.htm page like so:
<img src="../Home.png" />
Note the ".." which tells the browser to look in one directory up from where your html page is located.
be sure that the image and file in the same folder
and be sure that the name of image Home with H as capital letter