I'm new to PHP and coding in general, I already made the same lines of code in HTML and it worked fine but when i move it to PHP it wont load.
<div class="left">
<div class="healy-logo">
<img src="/asset/healy-logo.png" alt="">
</div>
<div class="doctor-logo">
<img src="/asset/doctor authen.png" alt="">
</div>
</div>
This is what is shown when i run the html code and my expectation for my php file
expectation
But when i run the PHP code it shows an error
error
Try this
<div class="left">
<div class="healy-logo">
<img src="asset/healy-logo.png" alt="">
</div>
<div class="doctor-logo">
<img src="asset/doctor authen.png" alt="">
</div>
</div>
If you use "/" in starting of a file path, It will take the first directory as the root directory of your system. this takes the relative path of your project directory
i think you just forget to run with Xampp or something like that (dont forget to click run Apache Server), or you just forgot to copy image folder/file on Xampp Folder.
or you just forget to add . if that all still not working you can do inside the HTMl and not HTML inside the
example for inside the HTML :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tes!</title>
<style>
body {
background-color: palevioletred;
color: white;
}
table {
text-align: center ;
}
</style>
</head>
<body>
<table border="1" cellspacing="10" cellpadding="10">
<?php
for ( $i = 10;
$i <= 100;
$i++
){
if ($i % 1) {
echo '<tr style="background-color: white;">';
}
for ($j = 1;
$j <= 100;
$j++
) {
echo "<center><td>Arsy I Love You</td></center>";
}
echo "</tr>";
}
?>
</table>
</body>
</html>
that's from me, hope thats help you bro!
Related
If I output an array in Route, the view I return afterwards stops working or shows only part of the content. I can pass the array to the view, but I'd like to be able to output arrays anywhere for debugging purposes.
View code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="https://code.jquery.com/jquery-3.6.0.slim.min.js"></script>
<link rel="stylesheet" href="{{ asset("css/main.css") }}">
</head>
<body>
<div style="max-width: 1200px; margin: 0 auto">
<nav class="menu">
<span>main</span>
<span>notes</span>
<span>users</span>
<span>login</span>
</nav>
</div>
</body>
</html>
And my output in browser:
<html lang="en">
<head></head>
<body>
Array([sad] => 111 [w] => Array([rrr] => ws))
<meta charset="utf-8">
<script src="https://code.jquery.com/jquery-3.6.0.slim.min.js"></script>
<link rel="stylesheet" href="/assets/css/main.css">
<div style="max-width: 1200px; margin: 0 auto">
<nav class="menu">
<span>main</span>
<span>notes</span>
<span>users</span>
<span></span>
</nav>
</div>
</body>
</html>
Also, if I display a line framed in double quotes and it contains [] characters, such as "example[example", in Route, view shows content with additional chunk of tag, such as < or </.
I tried to find something about it, but I couldn't. I use fresh install of laravel 9 without additions and PHP 8.1.7. What could be the problem?
I am developing my first PHP webapp on localhost. I am unable to refer to files in my sub-directories. For example, from any page of my project, if I have to call the following page, the image doesn't appear.
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Page is Under Construction</title>
</head>
<body>
<style>
.imgcontainer {
text-align: center;
margin: 10px 0 5px 0;
position: center;
}
</style>
<div class="imgcontainer" style="padding:0px;">
<img src="/myProjectRootFolder/images/under-construction.png" alt=""/>
</div>
</body>
</html>
The error message on Console is
UnderConstruction.php:25 GET http://localhost/myProjectRootFolder/images/under-construction.png 404 (Not Found)
could be you need a relative path
<img src="./myProjectRootFolder/images/under-construction.png" alt=""/>
or
<img src="./images/under-construction.png" alt=""/>
and be sure of your real image and pathnames ..
if your url for invoke the page is
/myProjectRootFolder/summary/salessummary.php
you should use the relative path
<img src="../images/under-construction.png" alt=""/>
then you should use
I am working a project that display product image. So to get more details about the products i put link, so when we hover the image we get a link like:
localhost/kbashop/display.html.php?name=alcatel.jpg
So how can i modify the above link to something like: localhost/kbashop/alcatel.html?
I have seen on many e-commerce site.
<?php
include_once'includes/connect.php';
try {
$sql = "SELECT filename FROM productlist LIMIT 4";
$s = $pdo->query($sql);
$result = $s->fetchAll(PDO::FETCH_ASSOC);
$counter = 0;
} catch (PDOException $e) {
$error = "Problem with your code".$e->getMessage();
}
?>
<!DOCTYPE html>
<html lang="fr" class="no-js">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Trouver un emploi rapidement.">
<meta name="auteur" content="kbajobs">
<head>
<title>KBASHOP</title>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
<style type="text/css">figcaption
{
text-align:center;
font-weight: bold;
font-size: 12px;
border: 2px solid olive;
padding-top: 5px;
}
</style>
</head>
<body>
<header>
<div class="logo">
<h1><b>KBA</b><strong>Shop.com</strong></h1>
</div>
</header>
<div class="main">
<div class="catalog cf">
<ul class="products">
<?php foreach($result as $row):
$name = $row['filename'];
list($width, $height) = getimagesize("images/thumbs/$name");
?>
<li>
<a href="display.html.php?name=<?php echo $name;?>">
<img src="images/thumbs/<?php echo $row['filename']?>" width="<?php echo $width;?>" height="<?php echo $height;?>"/>
</a>
</li>
<?php endforeach;?>
</ul>
</div>
</div>
<footer>
<div class="footer-info cf">
<p>© Copyright - Tous droits réservés aux test - 2015</p>
</div>
</footer>
</body>
<html>
Please any link to tutorial or tips or advise on this topics will really like saving.
So here i am putting my code for more help.
I've managed to achieve this by editing the .htaccess file in the root directory, adding some rewrite rules.
There are many ways of doing this depending on the URL you want to show. This URLs are called "friendly URLs". This one simple example will solve your specific request:
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /display.php?name=$1 [L]
You have to be aware that this rules tend to get more complicated depending on your friendly URLs requirements and project size.
One advice I would add is not to name your files .html.php. Keep things simple calling your HTML files with .html and your PHP files with .php
To get more documentation about this subject read about friendly URLs .htaccess rewrite rules.
Glad to help!
I have looked at other posts here regarding similar questions but cannot find an answer.
Edit I have been playing with this and I want to alter my question somewhat.
I am having a problem placing the output that is echoed from an external php file.
Here is some example code to demonstrate my problem - this is my main file writephp.php:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test Php </title>
<link rel="stylesheet" href="writephp.css">
</head>
<body>
<div class="allContent">
<?php for($i=0; $i<3; $i++): ?>
<div class="commentBox">
<p> Just a box</p>
</div>
<?php endfor; ?>
Php output
</div>
</body>
</html>
Now I can center this with css:
.allContent {
width: 400px;
margin-left: auto;
margin-right: auto;
font-family: Arial;
}
.commentBox {
border: 1px solid black;
width: 400px;
padding: 0px 5px 5px 5px;
margin-top: 5px;
}
So in the html file the php writes out boxes which are centered in the page since the php loop is within the "allConent" div.
The anchor envokes an external php file which will echo some more boxes.
That file looks like this and is called write.php (writephp.php is the main file this is called from):
<?php
if (isset($_GET['outputHtml']))
{
echo "<p class='allContent commentBox'>" . "This is from external PHP" . "</p>";
echo "<p class='allContent commentBox'>" . "This is also from external PHP" . "</p>";
include 'writephp.php';
}
But the echoed output from the external php is above the output from the main file -in fact it is placed before the <!doctype html> tag , obviously not good.
the page source looks like this:
<p class='commentBox allContent'>This is from external PHP</p
><p class='allContent commentBox'>This is also from external PHP</p>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test Php </title>
<link rel="stylesheet" href="writephp.css">
</head>
<body>
<div class="allContent">
<div class="commentBox">
<p> Just a box</p>
</div>
<div class="commentBox">
<p> Just a box</p>
</div>
<div class="commentBox">
<p> Just a box</p>
</div>
Php output
</div>
</body>
In general my question would be "how do I place html coming from an external php file anywhere I want on the page? "
<?php
if (isset($_GET['outputHtml']))
{
echo "<p class='commentBox'>" . "This is from external PHP" . "</p>";
echo "<p class='commentBox'>" . "This is also from external PHP" . "</p>";
include 'writephp.php';
}
This in your write.php is not correct, see writephp.php is a complete HTML page with <html> <head> and <body> tags and you are including it after echoing some <p> tags, that won't make your new boxes appear magically inside the body of the page, you would be creating some invalid markup with the two <p> at the beginning of the file followed by the <!DOCTYPE><html> etc...
EDIT
Regarding the update to your question that now reads "How place output from an external php file to a specific place on the page"
As #Robert Seddon-Smith correctly noted in his answer, using include will make the content appear exactly at the point when the call is made, so if you wanted to include your new boxes in your main file then the call to include should be backwards, that is, you should include the content inside the main file, you can use this example to test it:
Modify write.php to just echo the boxes when the $_GET variable is present
<?php
if (isset($_GET['outputHtml']))
{
echo "<div class='commentBox'>" . "This is from external PHP" . "</div>";
echo "<div class='commentBox'>" . "This is also from external PHP" . "</div>";
}
?>
And make the include call in your main file writephp.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test Php </title>
<link rel="stylesheet" href="writephp.css">
</head>
<body>
<div id="allContent">
<?php for($i=0; $i<3; $i++): ?>
<div class="commentBox">
<p> Just a box</p>
</div>
<?php endfor; ?>
<?php include 'write.php'?>
Php output
</div>
</body>
</html>
This will include your two new boxes inside the container when you click in the link.
Also you will note that there is nothing special about styling content from an included file, that is because in the end all the markup is rendered as a single HTML page, it doesn't matter if the content is echoed from the main page or the included file, it will obey any rules in your CSS
The problem is that you are not producing the correct content with write.php, probably due to a misunderstanding of what includes actually do.
All the include() function does is take the contents of the included file and parse it as PHP at the point in the file you include it. It has almost the same effect as cutting and pasting the file contents in the same place. Only put in your included file what you might type where it is to be put.
I would rewrite the lot properly so that write.php contains only a function that generates a string of html for your commment boxes:
<?PHP
function commentbox()
{
$output="";
for($i=0; $i<3; $i++)
$output.="<div class='commentBox' id='cb_$i'><p> Just a box</p></div>";
return $output;
}
?>
you include() this at the top of your php file then call its output wherever required by:
echo commentbox();
or, better:
create a footer.php file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test Php </title>
<link rel="stylesheet" href="writephp.css">
</head>
<body>
<div id="allContent">
<?PHP echo $content;?>
</div>
</body>
</html>
which you can use with all your projects very easily.
This is used this way:
<?PHP
include("write.php");
$content="whatever";
$content.=commentbox();
$content.="whateverelse";
include("footer.php");
?>
Even though I have deliberately gone to no trouble to format the above code, it is very easy to find where the content is being created and to debug it. Mixed PHP and HTML code is a nightmare to debug even with code-context-colouring. It is also very difficult to find the bit you want to borrow and put somewhere else later.
Firstly, you shouldn't be using the ID "allContent" on two separate elements. IDs are supposed to be unique. Classes can be used for styling multiple elements.
Why not change it to the code below? Is there a reason you want them to be different?
echo '<div class="commentBox"><p>' . 'This is from external PHP' . '</p></div>';
echo '<div class="commentBox"><p>' . 'This is also from external PHP' . '</p></div>';
I wonder whether someone may be able to help me please.
I'm using Aurigma's 'Image Uploader' software to allow users to add, and view images for the records they create with the image data collected and retrieved via an XML file.
One of the pages I've put together creates a gallery which allows the user to view the images, both individually and as part of a 'fancybox' slideshow. The script for this is shown below.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
$galleryPath = 'UploadedFiles/';
$thumbnailsPath = $galleryPath . 'Thumbnails/';
$absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR;
$descriptions = new DOMDocument('1.0');
$descriptions->load($absGalleryPath . 'files.xml');
?>
<head>
<title>Gallery</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="Libraries/fancybox/jquery.fancybox-1.3.1.css" rel="stylesheet" type="text/css" />
<link href="Styles/style.css" rel="stylesheet" type="text/css" />
<!--[if IE]>
<link href="Styles/ie.css" rel="stylesheet" type="text/css" />
<![endif]-->
<script src="Libraries/jquery/jquery-1.4.3.min.js" type="text/javascript"></script>
<script src="Libraries/fancybox/jquery.fancybox-1.3.1.pack.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() { $('a.fancybox').fancybox(); });
</script>
<style type="text/css">
<!--
.style1 {
font-size: 14px;
margin-right: 110px;
}
.style4 {font-size: 12px}
-->
</style>
</head>
<body style="font-family: Calibri; color: #505050; font-size: 9px; border-bottom-width: thin; margin-top: 5px; margin-left: -475px; margin-right: 1px; margin-bottom: -10px;">
<div align="right" class="style1"> <a href = "imagefolders.php" /> View Uploaded Images In Folder Structure <a/> ← View All Uploaded Images </div>
<form id="gallery" class="page">
<div id="container">
<div id="center">
<div class="aB">
<div class="aB-B">
<?php if ('Uploaded files' != $current['title']) :?>
<?php endif;?>
<div class="demo">
<div class="inner">
<div class="container">
<div class="gallery">
<ul class="gallery-image-list">
<?php for ($i = 0; $i < $descriptions->documentElement->childNodes->length; $i++) :
$xmlFile = $descriptions->documentElement->childNodes->item($i);
$name = htmlentities($xmlFile->getAttribute('originalname'), ENT_COMPAT, 'UTF-8');
$description = htmlentities($xmlFile->getAttribute('description'), ENT_COMPAT, 'UTF-8');
$folder = htmlentities($xmlFile->getAttribute('folder'), ENT_COMPAT, 'UTF-8');
$source = $galleryPath . rawurlencode($xmlFile->getAttribute('source'));
$thumbnail = $thumbnailsPath . rawurlencode($xmlFile->getAttribute('thumbnail'));
?>
<li class="item">
<a class="fancybox" target="_blank" rel="original" href="<?php echo $source; ?>"><img class="preview"
alt="<?php echo $name; ?>" src="<?php echo $thumbnail; ?>" /></a> </li>
<li class="item"></li>
<p><span class="style4"><b>Image Description:</b> <?php echo htmlentities($xmlFile->getAttribute('description'));?> <br />
<b>Image contained in folder:</b> <?php echo htmlentities($xmlFile->getAttribute('folder'));?> </span><br />
<?php endfor; ?>
</li>
</p>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="aB-a"> </div>
</div>
</div>
</div>
</form>
</body>
</html>
What I'd like to be able to do is now make the images that are retrieved, user specific, i.e. User A can only view their images.
If this information was being retrieved straight from a mySQL database I know that within PHP I can use the 'SELECT WHERE' statement to filter the returned records, but could someone tell me please is there an XML equivalent that I could use?
Many thanks
Allowing users to view only their own uploaded images is not such a simple task. If the images are stored in a publically accessable folder then anybody can view the images using their browser.
To achieve this there are a few alternatives such as:
storing the images in the database rather than the filesystem,
creating a new foler for each user on the filesystem and changing
the read write permissions for each folder, or
storing the images outside the web root and fetching the images
using php i.e.
Instead of providing a link to an image. Provide a link to a cgi
script which will automatically provide the proper header and
content of the image.
For example: image.php?sample.jpg
You can then make sure they are already authenticated (e.g. pass a
session id) as part of the link.
This would be part of the header, and then your image data can
follow.
<?php
$file = basename(urldecode($_GET['file']));
$fileDir = '/path/to/files/';
if (file_exists($fileDir . $file))
{
//perform some authorisation check
...
...
// Note: You should probably do some more checks
// on the filetype, size, etc.
$contents = file_get_contents($fileDir . $file);
// Note: You should probably implement some kind
// of check on filetype
header('Content-type: image/jpeg');
echo $contents;
}
?>