I wonder whether someone may be able to help me please.
I'm trying to load an xml file with the following filepath:
/UploadedFiles/username/location/files.xml
What I've been trying to do for some time, is to use the values of two forms fields, 'username' and 'location' and incorporate them into the filepath, but I just can't seem to get this right.
I just wondered whether someone could someone perhaps tell me how I take these values and use them in the filepath.
Many thanks
POST AMENDMENT
I thought I could solve my issues by simply changing the file path, hence my original post, but I fear my lack of PHP knowledge as let me down and I suspect the issues I have are deeper within my code.
Please find below more detail.
The script below shows how I initially save the images.
'upload.php'
<?php
require_once 'Includes/gallery_helper.php';
require_once 'ImageUploaderPHP/UploadHandler.class.php';
$galleryPath = 'UploadedFiles/';
function onFileUploaded($uploadedFile) {
global $galleryPath;
$packageFields = $uploadedFile->getPackage()->getPackageFields();
$username=$packageFields["username"];
$locationid=$packageFields["locationid"];
$username = preg_replace('/[^a-z0-9_\-\.()\[\]{}]/i', '_', $_POST['username']);
$location = preg_replace('/[^a-z0-9_\-\.()\[\]{}]/i', '_', $_POST['locationid']);
$dirName = preg_replace('/[^a-z0-9_\-\.()\[\]{}]/i', '_', $_POST['folder']);
$absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR . $username . DIRECTORY_SEPARATOR . $location . DIRECTORY_SEPARATOR;
$absThumbnailsPath = $absGalleryPath . 'Thumbnails' . DIRECTORY_SEPARATOR;
if (!is_dir($absGalleryPath)) mkdir($absGalleryPath, 0777, true);
chmod($absGalleryPath, 0777);
if (!is_dir($absGalleryPath . $dirName)) mkdir($absGalleryPath . $dirName, 0777, true);
chmod($absGalleryPath . $dirName, 0777);
if ($uploadedFile->getPackage()->getPackageIndex() == 0 && $uploadedFile->getIndex() == 0)
initGallery($absGalleryPath, $absThumbnailsPath, FALSE);
$originalFileName = $uploadedFile->getSourceName();
$files = $uploadedFile->getConvertedFiles();
$sourceFileName = getSafeFileName($absGalleryPath, $originalFileName);
$sourceFile = $files[0];
if ($sourceFile) $sourceFile->moveTo($absGalleryPath . $sourceFileName);
$thumbnailFileName = getSafeFileName($absThumbnailsPath, $originalFileName);
$thumbnailFile = $files[1];
if ($thumbnailFile) $thumbnailFile->moveTo($absThumbnailsPath . $thumbnailFileName);
$descriptions = new DOMDocument('1.0', 'utf-8');
$descriptions->load($absGalleryPath . 'files.xml');
$xmlFile = $descriptions->createElement('file');
// <-- please check the following line
$xmlFile->setAttribute('name', $_POST['folder'] . '/' . $originalFileName);
$xmlFile->setAttribute('source', $sourceFileName);
$xmlFile->setAttribute('size', $uploadedFile->getSourceSize());
$xmlFile->setAttribute('originalname', $originalFileName);
$xmlFile->setAttribute('thumbnail', $thumbnailFileName);
$xmlFile->setAttribute('description', $uploadedFile->getDescription());
$xmlFile->setAttribute('username', $username);
$xmlFile->setAttribute('locationid', $locationid);
$xmlFile->setAttribute('folder', $dirName);
$descriptions->documentElement->appendChild($xmlFile);
$descriptions->save($absGalleryPath . 'files.xml');
}
$uh = new UploadHandler();
$uh->setFileUploadedCallback('onFileUploaded');
$uh->processRequest();
?>
This script produces the following file structure:
UploadedFiles (Pre-existing folder)
'username' (Subfolder containing 'location' folder)
'location' (Subfolder containing original image, 'files.xml' and 'Thumbnails' folder)
'Thumbnails' (Subfolder containing thumbnail of original image)
NB. The 'username' and 'location folder names are derived from the current user and location values.
I then come onto my issue with the creation of the image gallery.
The code below is my initial 'gallery.php' script. I need to change the top PHP section of the script to match the new folder structure i.e. UploadedFiles/'username'/'location'/Thumbnails and UploadedFiles/'username'/'location'.files.xml
'gallery.php'
<?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: -476px; 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">
<input name="username" type="text" id="username" value="IRHM73" />
<input name="locationid" type="text" id="locationid" value="1" />
<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>
<p><span class="style4"><b>Image Description:</b> <?php echo htmlentities($xmlFile->getAttribute('description'));?> <br />
<b>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>
I admit to being at a real loss at how to solve this, I don't whether it's my 'gallery.php' script that needs to change or my 'upload.php'
Any help would be so gratefully received.
Kind regards
OK, let's say you have this values : username, location.
Then, (if I get your question right) in the responding script (the one receiving the form action), try this :
<?php
$username = $_GET['username'];
$location = $_GET['location'];
$filepath = "/UploadedFiles/$username/$location/files.xml";
?>
Hint (2 ways of concatenating strings) :
$filepath = "/UploadedFiles/$username/$location/files.xml";
OR
$filepath = "/UploadedFiles/".$username."/".$location."/files.xml";
This will work regardless you are using post or get method in your form . Just make sure you choose field name username and location for input text html element.
$filepath = "/UploadedFiles/{$_REQUEST['username']}/{$_REQUEST['location']}/files.xml"
You have to define them as variable and include within the string
$username = "user1";
$location = "userlocation1";
$url = "/UploadedFiles/$username/$location/files.xml";
//Next you might want to verify the location
if(is_file($url)) {
//do your operation....
}
Related
I am making a website that automaticly generates a html with some text that you can fill in a form.
but I want that text back in the form once I press a button or something, so you can edit it.
I tried it with fread and fwrite, Javascript and some more.
I use $_POST and I cut out the form of the php file.
<?php
if($_SERVER["REQUEST_METHOD"] == "POST")
{
mkdir($_POST['naam'], 0777);
if (!mkdir($_POST['naam'], 0777))
{
$uploaddir = $_POST['naam']."/";
$uploadfile = $uploaddir . basename($_FILES['logo']
['name']);
if(move_uploaded_file($_FILES['logo']['tmp_name'],
$uploadfile)) {
echo $uploadfile;
echo " succesfull";
$file = fopen($_POST['naam']."/index.html", "w");
$code = $code = "<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<title>".$_POST['naam']."</title>
</head>
<body>
<main>
<img src='".$_FILES['logo']['name']."'/>
<h1 name='naam'>".$_POST['naam']."</h1>
<div class='contact'>
<h3>Telefoon: <span id='Telefoon'>".$_POST['Telefoon']."<span></h3>
<h3>Email: <span id='Email'>".$_POST['Email']."</span></h3>
<h3>Straat: <span ide='straat'>".$_POST['straat']."</span></h3>
<h3>plaats: <span id='plaats'>".$_POST['plaats']."</span></h3>
</div>
<p class='info'><span id='overig'>".$_POST['overig']."</span></p>
<p class='melding'>Wij zijn bezig aan onze website, coming soon</p>
</main>
</body>
</html>";
fwrite($file, $code);
fclose($file);
}
}
else
{
echo "failed";
}
}
?>
You have your variable - $code - so simply create a new form with something like this
<textarea name="full>".$code."</textarea>
I think you are just missing echo statements to output the server values:
<h3>Telefoon: <span id='Telefoon'>". echo($_POST['Telefoon']) ."<span></h3>
Why I cant display the data I echo from the database in a PDF file ?
I used DOMPDF to convert my html. Anyone please help.
Here is the PDF result
PDF result image
Here is connection code
<?php
$id = $_GET['id'];
$conn = pg_connect("host=localhost dbname=mydatabase user=postgres password=admin");
if (!$conn) {
echo "An error occurred. cannot connectect to localhost.\n";
exit;
}
$sql = pg_query($conn, "SELECT * FROM mytable WHERE reference_no = $id ");
if (!$sql) {
echo "Error Ariel 7:50 !!!.\n";
}
while ($row = pg_fetch_assoc($sql)) {
$reference_no = $row['reference_no'];
$wo_name = $row['wo_name'];
}
Here is my convertion code:
error_reporting(0);
require_once ('xdompdf/dompdf_config.inc.php');
$pdf_content='
<style type="text/css">
div.refno{padding-left: 190px;}
.line{padding-left: 260px; padding-top: -37px;}
</style>
<body>
<div>
<h4> Work Order Form </h4>
<p> Reference No. <div class="refno"><?php echo $reference_no;?></div> </p>
<p class="line">:_________________________________________________</p>
<p> Work Order Name <div class="woname"><?php echo $wo_name;?></div> </p>
<p class="line">:_________________________________________________</p>
</div>
</body>'
;
$name = date("Ymd").rand().'.pdf';
$reportPDF=createPDF(12, $pdf_content, 'activity_Report', $name );
function createPDF($pdf_userid, $pdf_content, $pdf_For, $filename){
$path='xdompdf/';
/*$rndNumber=rand();
$filename=$pdf_userid.date("Ymd").$rndNumber.'.pdf';*/
$dompdf=new DOMPDF();
$dompdf->load_html($pdf_content);
$dompdf->render();
$output = $dompdf->output();
file_put_contents($path.$filename, $output);
return $filename;
}
echo '<a href="xdompdf/'.$name.'" > Download </a>';
?>
Please Help me how to display the data.
Change $pdf_content to
$pdf_content='
<style type="text/css">
div.refno{padding-left: 190px;}
.line{padding-left: 260px; padding-top: -37px;}
</style>
<body>
<div>
<h4> Work Order Form </h4>
<p> Reference No. <div class="refno">' . $reference_no . '</div> </p>
<p class="line">:_________________________________________________</p>
<p> Work Order Name <div class="woname">' . $wo_name . '</div> </p>
<p class="line">:_________________________________________________</p>
</div>
</body>';
I think you just need to concat your data in $pdf_content :
$pdf_content='
<style type="text/css">
div.refno{padding-left: 190px;}
.line{padding-left: 260px; padding-top: -37px;}
</style>
<body>
<div>
<h4> Work Order Form </h4>
<p> Reference No. <div class="refno">'.$reference_no.'</div> </p>
<p class="line">:_________________________________________________</p>
<p> Work Order Name <div class="woname">'.$wo_name.'</div> </p>
<p class="line">:_________________________________________________</p>
</div>
</body>';
I am running a localhost website using Flask and python. I have some php files that I want to run when the users click a button. Problem is that Flask isn't recognizing the PHP file as PHP code and the code is showing up as text on the webpage. It's showing the text of all the echo statements, but the words in those statements correspond to variable in the code that allow the user to login and logout of the website. What do I do?
Python Code:
#app.route('/example.php')
def phpexample():
return render_template('example.php')
This shows a html page with text resulting from the echo statements.
The PHP code (example.php):
<?php
require ('steamauth/steamauth.php');
?>
<html>
<head>
<title>Eliminate Phishers! Join Steap now</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<!--[if lte IE 8]><script src="css/ie/html5shiv.js"></script><![endif]-->
<script src="js/jquery.min.js"></script>
<script src="js/skel.min.js"></script>
<script src="js/init.js"></script>
<noscript>
<link rel="stylesheet" href="css/skel.css" />
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/style-wide.css" />
</noscript>
<!--[if lte IE 8]><link rel="stylesheet" href="css/ie/v8.css" /><![endif]-->
</head>
<body>
<!-- Header -->
<div id="header">
<span class="logo icon fa-paper-plane-o"></span>
<h1>Welcome. This is Steap</h1>
<p>A website designed to help eliminate phishers
<br />
and hackers on Steam.</p>
</div>
<!-- Main -->
<div id="main">
<header class="major container small">
<h3>
<?php
if(!isset($_SESSION['steamid'])) {
echo "welcome guest! <br />\n please login ";
steamlogin(); //login button
} else {
include ('steamauth/userInfo.php');
$url = $steamprofile['profileurl'];
if ($steamprofile['personastate'] == 0) {
$state = '<span style="color:#616161";>(Offline)</span>';
$picture = '<span style="color:#616161";><img src="'.$steamprofile['avatarfull'].'" title = "" alt = ""></span>';
} else if ($steamprofile['personastate'] == 1) {
$state = '<span style="color:#006EFF";>(Online)</span>';
$picture = '<span style="border: 10px dotted #006EFF;"><img src="'.$steamprofile['avatarfull'].'" title = "" alt = ""></span>';
} else if ($steamprofile['personastate'] == 2) {
$state = '<span style="color:#006EFF";>(Busy)</span>';
$picture = '<span style="border-color:#006EFF border-style: solid";><img src="'.$steamprofile['avatarfull'].'" title = "" alt = ""></span>';
} else if ($steamprofile['personastate'] == 3) {
$state = '<span style="color:#006EFF";>(Away)</span>';
$picture = '<span style="border-color:#006EFF border-style: solid";><img src="'.$steamprofile['avatarfull'].'" title = "" alt = ""></span>';
} else if ($steamprofile['personastate'] == 4) {
$state = '<span style="color:#006EFF";>(Snooze)</span>';
$picture = '<span style="border-color:#006EFF border-style: solid";><img src="'.$steamprofile['avatarfull'].'" title = "" alt = ""></span>';
} else if ($steamprofile['personastate'] == 5) {
$state = '<span style="color:#006EFF";>(Looking to Trade)</span>';
$picture = '<span style="border-color:#006EFF border-style: solid";><img src="'.$steamprofile['avatarfull'].'" title = "" alt = ""></span>';
} else if ($steamprofile['personastate'] == 6) {
$state = '<span style="color:#006EFF";>(Looking to Play)</span>';
$picture = '<span style="border-color:#006EFF border-style: solid";><img src="'.$steamprofile['avatarfull'].'" title = "" alt = ""></span>';
}
//Protected content
echo "Welcome back" . "</br> </br>" . $picture ."</br>". $steamprofile['personaname'] . "</br>" .$state . "</br>". "Steam ID: ". $steamprofile['steamid'] . "</br>";
echo 'Steam Profile' . "</br> </br>" . "<form action=\"steamauth/logout.php\" method=\"post\"><input value=\"Logout\" type=\"submit\" /></form>"; // Display their avatar!
}
?>
</h3>
</header>
<footer class="major container small">
<ul class="actions">
<li>Get Phishers</li>
</ul>
</footer>
</div>
<!-- Footer -->
<div id="footer">
<div class="container small">
<header class="major last">
<h2>Questions or comments?</h2>
</header>
<p>Program not working? Not detecting the phishers properly? <br \> Send us a message. We'll be sure to back to you as soon as possible.</p>
<form method="post" action="#">
<div class="row collapse-at-2">
<div class="6u">
<input type="text" name="name" placeholder="Name" />
</div>
<div class="6u">
<input type="email" name="email" placeholder="Email" />
</div>
</div>
<div class="row">
<div class="12u">
<textarea name="message" placeholder="Message" rows="6"></textarea>
</div>
</div>
<div class="row">
<div class="12u">
<ul class="actions">
<li><input type="submit" value="Send Message" /></li>
</ul>
</div>
</div>
</form>
<ul class="icons">
<li><span class="label">Twitter</span></li>
<li><span class="label">Facebook</span></li>
<li><span class="label">Instagram</span></li>
<li><span class="label">Github</span></li>
<li><span class="label">Dribbble</span></li>
</ul>
<ul class="copyright">
<li>© Steap 2014 All rights reserved.</li><li>Design: HTML5 UP</li>
</ul>
</div>
</div>
</body>
</html>
Maybe you should run php server (such as Apache or another) on other port (such as 8080) and when you call any php file, make request from your flask server to php server. And result getting from php server show with flask server. I hope, you can find the way how to send request from flask to other server.
render_template() isn't support PHP.
You can use subprocess to run PHP script:
import subprocess as sp
#app.route('/example.php')
def phpexample():
out = sp.run(["php", "example.php"], stdout=sp.PIPE)
return out.stdout
Flask is not compatible with php. So it can't read php code.
Have you considered using JQuery Ajax?
Here's an example:
You have a file called get_name.php witch contains:
<?php echo "Hello, my name is John"; ?>
Using Jquery ajax function I call the get_name.php
$.ajax({
url : 'get_name.php',
success : function(data) {
console.log(data);
}
});
The output in the console would be:
Hello, my name is John
So, with the returned data you can do whatever you want.
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
Can someone help me connect some code??
What I want is a code that does this: If a picture exist then print it, else don't print anything.
(This code is used to find the pichure)
and I need help to conect the if statment to the one in the other code
<?php
$pathToFileOnDisk = 'inventory_images/' . $id . '.jpg';
if(file_exists($pathToFileOnDisk) && is_readable($pathToFileOnDisk)) {
<img src="inventory_images/' . $id . '.jpg" alt="' . $name . '" width="100%" height="260" border="1" />
}
else {
// NO IMG
}
?>
AND
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
// Run a select query to get my letest 6 items
// Connect to the MySQL database
include "storescripts/connect_to_mysql.php";
$dynamicList = "";
$sql = mysql_query("SELECT * FROM content ORDER BY id DESC LIMIT 6");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$name = $row["name"];
$content = $row["content"];
$date_added = strftime("%d %b, %Y", strtotime($row["date_added"]));
$dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<div id="left">
<img src="inventory_images/' . $id . '.jpg" alt="' . $name . '" width="100%" height="260" border="1" /> <-- !!THIS IS WHAT I WANNA REPLACE!!
</div> <!-- End Left-->
</td>
<div id="right">
<td width="630px" valign="top"><h2><a id="overskrift" href="product.php?id=' . $id . '">' . $name . '</a></h2>
<p><b>
Skrevet den ' . $date_added . '<br />
' . $content . '</b></p>
</td>
</div>
</tr>
</table><br />';
}
} else {
$dynamicList = "Ingen inlegg enda..";
}
mysql_close();
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen" />
</head>
<body>
<div id="wrapper">
<header>
<?php include_once("template_header.php");?>
</header> <!-- End Header -->
<div id="banner"></div>
<div class="content test clearfix">
<?php echo $dynamicList; ?>
</div> <!-- End Content -->
<footer>
<?php include_once("template_footer.php");?>
</footer> <!-- End Footer -->
</div> <!-- End Wrapper -->
</body>
Use the file_exists() and is_readable() functions.
The first will tell if the file exists, and the second will tell if you have permissions to read the file, before actually doing it. Similarly, there's also the is_writable() function, which tells you if you have permissions to write to a file.
Simply use this:-
<?php
$filename = 'some_name';
if (file_exists($filename)) {
echo "File exists";
} else {
echo "File does not exist";
}
?>
The file_exists and is_readable functions are perfect for this purpose.
For example:
<?php
$pathToFileOnDisk = '/full/system/path/to/image.jpg';
if(file_exists($pathToFileOnDisk) && is_readable($pathToFileOnDisk)) {
// The file exists and can be read
}
else {
// The file doesn't exist (or does exist, but PHP can't read it).
// Perhaps output a placeholder image here.
}
?>
Incidentally, I'd recommend a quick glance at all of the filesystem functions, as the time spent on this now will pay dividends in the future.