I am trying to copy a website to my local machine. I have downloaded all the code, and things like page redirection, and importing work fine. But displaying images, css, and using javascript doesn't seem to work.
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
include ($root . '/resources/config.php');
echo "$imagepath/user_suit.png";
?>
<div class="sidebar1">
<ul class="nav">
<li>
<div id="loginLink" class="menu" onmousedown="return false;" >
<img src="
<?php
echo $imagepath
?>/user_suit.png" width="15" height="14" alt="Member Login"> Member Login
</div>
</li>
</ul>
Welcome Guest!
</div>
<script type="text/javascript">
$("#loginLink").click(function(){
// load contact form onclick
$("#contentPane").hide();
$("#loadingPageGif").show();
$("#contentPane").load("
<?php
echo $server
?>/code/login/Studentlogin.php",
function() {
$("#loadingPageGif").hide();
$("#contentPane").fadeIn();
});
});
</script>
In this code, the embedded image does not load, and clicking on the link does nothing.
I can right click on the unloaded image, go to view image, and it correctly displays.
I can put echo lines in $root . '/resources/config.php' and they show up correctly.
The site I downloaded it from does not have these issues, so I am guessing it has something to do with xampp.
The browser adds http://, you should make that
<div id="loginLink" class="menu" onmousedown="return false;" > <img src="http://localhost:82/public_html/images/user_suit.png" width="15" height="14" alt="Member Login"> Member Login </div>
Related
I have built a site for someone else who will be updating it via a CMS (CushyCMS). They wanted a lightbox gallery included. I want to be able to allow them to upload a new image and for that image url to be copied into the a tag so lightbox works.
So far I am able to do that, but the client has to ensure the file names and format are exactly the same as what I have set them to in the php code. Is there a way to get the img url from the img tag (possibly identifying it using an id attribute) and put it directly into the tag?
Heres what I have so far:
<?php
$src1 = "images/test1.jpg";
$src2 = "images/test2.jpg";
?>
<a href="<?php echo $src1?>" data-lightbox="group-1">
<img class="cushycms profile" name="image1" id="slideshow_image" src="images/test1.jpg"/></a>
<a href="<?php echo $src2?>" data-lightbox="group-1">
<img class="cushycms profile" id="slideshow_image" src="images/test2.jpg"/></a>
Many thanks!
You can do it with jQuery:
<a data-lightbox="group-1">
<img name="image1" src="images/test1.jpg" />
</a>
<script>
var img = $('img[name="image1"]');
var imgSrc = img.attr('src');
img.parent().attr('href', imgSrc);
</script>
If you have multiple images and want to automate this you can use the map function:
<a data-lightbox="group-1">
<img name="image1" src="images/test1.jpg" class="slideshow" />
</a>
<a data-lightbox="group-1">
<img name="image2" src="images/test2.jpg" class="slideshow" />
</a>
<a data-lightbox="group-1">
<img name="image3" src="images/test3.jpg" class="slideshow" />
</a>
<script>
$(".slideshow").map(function() {
$(this).parent().attr('href', this.src);
});
</script>
Assuming you use jQuery somewhere there, you could/should use a lightbox plugin, like this one here:
http://www.jacklmoore.com/colorbox/
Using the xamples there, you would then use:
(http://www.jacklmoore.com/colorbox/example1/)
$('a.gallery').colorbox({rel:'group-1'});
which would result in a lighbox gallery showing on "click" on any anchor with class "gallery" while the gallery would show all the elements pointed by "href" from all anchors of that have class="group-1" (so each anchor would be
although you have to include some files for jquery and the lightbox plugin, I think it will make your life much easier in the end.
Also not sure what your php level is, but the example code you have there asks for:
<?php
$images = array(
'images/test1.jpg',
'images/test2.jpg'
);
?>
<?php foreach($images as $i => $url): ?>
<a href="<?php echo $url?>" data-lightbox="group-1">
<img class="cushycms profile" name="image<?php echo $i+1 ?>" id="slideshow_image" src="<?php echo $url ?>"/>
</a>
<?php endforeach; ?>
Just in case you got more images there.
I am using a PHP Framework for the first time to get away from writing spaghetti code and so far it is wonderful. I am using Code Igniter and have a base Controller named "Dashboard.php" that loads fine and looks perfect.
When attempting to create some organization, I placed my "Devices.php" into a "Controllers/Devices" sub-folder, then accessed it at "http://domain.com/devices/devices" which loads the text, but the images/css/etc. are missing.
The content of the "Devices" controller is exactly the same as my "Dashboard" so I am not understanding why only the text loads. If I move the "devices.php" file into the root Controllers directory, there are no problems.
class Devices extends CI_Controller
{
public function index()
{
$data['page_title'] = 'Device Portal';
$this->load->view('meta');
$this->load->view('sidebar');
$this->load->view('userbar');
$this->load->view('header');
$this->load->view('devices/content');
$this->load->view('footer');
}
}
Here is the "Sidebar.php" View...
<!-- Left side content -->
<div id="leftSide">
<div class="logo"><img src="assets/images/logo.png" alt="" /></div>
<div class="sidebarSep mt0"></div>
<!-- Search widget -->
<form action="" class="sidebarSearch">
<input type="text" name="search" placeholder="search..." id="ac" />
<input type="submit" value="" />
</form>
<div class="sidebarSep"></div>
<!-- General balance widget -->
<div class="genBalance">
<a href="#" title="" class="amount">
<span>General balance:</span>
<span class="balanceAmount">$10,900.36</span>
</a>
<a href="#" title="" class="amChanges">
<strong class="sPositive">+0.6%</strong>
</a>
</div>
You need to avoid using relative paths when linking to images/css/etc in your views.
As an example, when you use assets/images/logo.png (relative path) from the page http://domain.com/devices/devices, the browser looks for http://domain.com/devices/assets/images/logo.png
Using the same image path with the page http://domain.com/devices the browser will look for http://domain.com/assets/images/logo.png instead.
When specifying urls to pages, images, etc within your domain, use the URL helper functions to automatically format your urls.
You want to avoid writing urls like this:
<script type="text/javascript" src="./assets/js/jquery.js"></script>
<img src="assets/images/logo.png" alt="" />
And instead generate your urls like this:
<script type="text/javascript" src="<?php echo base_url('assets/jquery.js'); ?>"></script>
<img src="<?php echo base_url('assets/images/logo.png'); ?>" alt="" />
Which will output:
<script type="text/javascript" src="http://domain.com/assets/js/jquery.js"></script>
<img src="http://domain.com/assets/images/logo.png" alt="" />
In Codeigniter use base_url() function to print assets.
<img src="<?php echo base_url('assets/images/logo.png');?>" alt="" />
This function automatically generate domain before the url.
i'am using wordpress and the nextGen Gallery plugin version 1.9.13 and i read out the galleries by code with this code:
$newnggShortcodes = new NextGEN_Shortcodes;
echo $newnggShortcodes->show_gallery( array("id"=>$currGalId,"template"=>"mygallery") );
this works fine, then i can click on the image and it pops up but then i can't click to next or previous image, it only pop up the one i have clicked.
when i check out the code, the rel tag is there, i looks like this:
<div id="ngg-gallery-10-112" class="ngg-galleryoverview">
<div id="ngg-image-256" class="ngg-gallery-thumbnail-box">
<div class="ngg-gallery-thumbnail">
<a class="cboxElement" rel="lightbox[set_10]" title=" " href="PATH-TO-IMAGE.jpg">
<img class="colorbox-manual" width="420" height="200" src="PATH-TO-IMAGE.jpg.jpg" alt="dsc_0007" title="dsc_0007">
</a>
</div>
</div>
<div id="ngg-image-257" class="ngg-gallery-thumbnail-box">
<div class="ngg-gallery-thumbnail">
<a class="cboxElement" rel="lightbox[set_10]" title=" " href="http://PATH-TO-IMAGE.jpg.jpg">
<img class="colorbox-manual" width="420" height="200" src="http://PATH-TO-IMAGE.jpg.jpg" alt="dsc_0008" title="dsc_0008">
</a>
</div>
</div>
when i use the [nggallery id=10] in the backend, the it works fine.
anyone a idea?
thanks!
I found the mistake, the problem was not nextGen Gallery, the problem was that i use the jquery colorbox and the colorbox recognized it as single picture.
so I have my main layout as such:
<div class="menu">
<?php include('/menu.php'); ?>
</div>
<div class="main" id="content">
<?php include('/home.php'); ?>
</div>
In the menu.php I have 4 divs set up as such:
<div class="link current">
<a href="#" class="home">
Home
</a>
</div>
<div class="link">
<a href="#" class="about">
About
</a>
</div>
<div class="link">
<a href="#" class="forums">
Forums
</a>
</div>
<div class="link">
<a href="#" class="contact">
Contact
</a>
</div>
And I'm including this .js file in the head of the index page
$(function () {
$('div.link a').click(function () {
$('div.link').removeClass('current');
$(this).closest('div.link').addClass('current');
if($('div.link a').hasClass('home')) {
$('#content').load('/home.php');
} else if($('div.link a').hasClass('about')) {
$('#content').load('/about.php');
} else if($('div.link a').hasClass('forums')) {
$('#content').load('/forums.php');
} else if($('div.link a').hasClass('contact')) {
$('#content').load('/contact.php');
} else return false;
});
});
But it doesn't work.
I'm new to all of this and have pieced this code together using varied sources on the internet, after trying it myself and not being able to figure it out, I've come for help.
The hierarchy of the site is as such.
-/
-res/
-css/
-default.css
-imgs/
-scripts/
-jquery.js
-load.js (this is the one shown above)
-index.php
-menu.php
-home.php
-about.php
-forums.php
-contact.php
If anyone can provide help, it will be greatly appreciated.
The first condition in your if statements is checking to see if any "div.link a" has the class "home". Therefore the first if condition is always true and you're always loading /home.php into #content. What you want to do is check to see if the link that was clicked has the class.
You should use if($(this).hasClass('home')) { ...
Also, if you want to clean things up a bit, I would suggest:
$('div.link a').click(function () {
$('div.link').removeClass('current');
$(this).closest('div.link').addClass('current');
$('#content').load('/' + $(this).attr('class') + '.php');
});
This way you don't have to maintain the if statements. Though, if you end up adding more classes to those links, this will break. Perhaps use a data-* attribute? <a href="#" data-load="contact">...
I'm trying to limit maintnance headaches by avoiding having to copy and paste code and having to update it on several different sites. Should I use an iframe? So far I just used inline CSS to style it and plan on copying a pasting to 3 or 4 other sites. Kind of like:
<div style="width:165px; height:40px; background: url('http://site1.com/images/DH-sharebar.gif') repeat-x top #333;float:right;margin-top:15px;margin-right:20px;border-radius:5px;border:1px #565656 solid;">
<a href="http://site1.com/" target="_blank" title="site 1">
<img src="http://davidhairabedian.com/davidhairabedian/images/DH-sharebar-icon.png" style="border-radius:0;margin-top:5px;margin-left:10px;">
</a>
<a href="http://site2.org/" target="_blank" title="site 2">
<img src="http://site1.com/images/DH-sharebar-HPM-icon.png" style="border-radius:0;margin-top:5px;margin-left:10px;">
</a>
<a href="http://site3.org/" target="_blank" title="site 3">
<img src="http://site1.com/images/DH-sharbar-EHF.png" style="border-radius:0;margin-top:5px;margin-left:3px;">
</a>
<a href="http://site4.org/" target="_blank" title="site 4">
<img src="http://site1.com/images/DH-sharebar-EHC.png" style="border-radius:0;margin-top:5px;margin-left:10px;">
</a>
</div>
If you don't mind having a slight delay, you could write a light JavaScript that loaded the content into the page via AJAX, much like facebook / many other widgets do.
The benefit that offsets the fact that your links are not part of the page's initial HTML is the fact that you can update the content of all widgets from one place, with no chance that you'll forget one int he future.
Have a look into how Facebook / Google + / Twitter / Everyone else does this.
Edit
Your question got me thinking about how one might do this, so I did it. I've made a working JSFiddle example.
Basically, you paste an empty div and a script tag into your target pages. The script references a file stored on your central server. It creates another script tag in the document, which itself contains a call to a function defined in the first script, which inserts your widget into the specified div on the page.
Pasted into your pages
<div id="placeholder-div"></div>
<script type="text/javascript" src="http://pagesofinterest.net/stack-examples/what-would-be-the-best-way-to-make-a-widget-that-will-link-to-4-different-websit/script.js"></script>
First script content
(function loadContent() {
(function xss_ajax(url) {
var script_id = null;
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', 'http://pagesofinterest.net/stack-examples/what-would-be-the-best-way-to-make-a-widget-that-will-link-to-4-different-websit/content.php');
script.setAttribute('id', 'script_id');
script_id = document.getElementById('script_id');
if(script_id){
document.getElementsByTagName('head')[0].removeChild(script_id);
}
// Insert <script> into DOM
document.getElementsByTagName('head')[0].appendChild(script);
})();
})();
function callback(data) {
document.getElementById('placeholder-div').innerHTML = data;
}
Inserted script content:
<?php ob_start(); ?>
<div style="width:165px; height:40px; background: url('http://site1.com/images/DH-sharebar.gif') repeat-x top #333;float:right;margin-top:15px;margin-right:20px;border-radius:5px;border:1px #565656 solid;">
<a href="http://site1.com/" target="_blank" title="site 1">
<img src="http://davidhairabedian.com/davidhairabedian/images/DH-sharebar-icon.png" style="border-radius:0;margin-top:5px;margin-left:10px;"/>
</a>
<a href="http://site2.org/" target="_blank" title="site 2">
<img src="http://site1.com/images/DH-sharebar-HPM-icon.png" style="border-radius:0;margin-top:5px;margin-left:10px;"/>
</a>
<a href="http://site3.org/" target="_blank" title="site 3">
<img src="http://site1.com/images/DH-sharbar-EHF.png" style="border-radius:0;margin-top:5px;margin-left:3px;"/>
</a>
<a href="http://site4.org/" target="_blank" title="site 4">
<img src="http://site1.com/images/DH-sharebar-EHC.png" style="border-radius:0;margin-top:5px;margin-left:10px;"/>
</a>
</div>
<?php $content = json_encode(ob_get_clean());
echo "callback($content);";
And after all this, it occurred to me that you could just use an iframe:
<iframe src="http://pagesofinterest.net/stack-examples/what-would-be-the-best-way-to-make-a-widget-that-will-link-to-4-different-websit/iframe.html"></iframe>
Personally, I would use the JavaScript method, as this would allow me to modify the style of the widget whenever I wanted, without requiring my users to update their pages.