I need help in displaying my images from the directory images on my public_html directory. It's been uploaded, but it doesn't appear when I run the below php script. Please does anyone know why?
<?php
include_once("connect.php");
?>
<!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" />
<title>Untitled Document</title>
</head>
<body>
<?php
//Retrieves data from MySQL
$data = mysql_query("SELECT * FROM authors") or die(mysql_error());
//Puts it into an array
while($info = mysql_fetch_array( $data ))
{
Echo "<img src=http://giveaway.comli.com/public_html/images/".$info['photo']."> <br>";
Echo "<b>Name:</b> ".$info['name'] . "<br> ";
Echo "<b>Title:</b> ".$info['title'] . " <br>";
Echo "<b>Phone:</b> ".$info['description'] . " <br>";
Echo "<b>Link<br>";
Echo "<b>Country:</b> ".$info['country'] . " <hr>";
}
?>
</body>
</html>
Is your public_html directory really not your site's document root? Perhaps you mean to say:
Echo "<img src=http://giveaway.comli.com/images/".$info['photo']."> <br>";
Where /images is a directory at the site document root. In a typical hosting situation, public_html would be the site document root, meaning that referenced from the web (rather than the file system), it is /.
What is the document root of your site? I'm guessing it's /home/.../public_html, which means the URL to access the images would really be http://giveaway.comli.com/images. Absolute urls of the sort you're using are really only necessary if you're using multiple different hosts/servers for your site, and/or are intending for the html to be portable. You could probably get away with using just <img src="/images/...">.
As I can see your document roo directory is public_html, so URL path to your photo will be look like this $image_url = "/images/" . $info['photo'];
Related
I am trying to create a template html page which I will call via an include to set to a variable, this variable will then be used to set the value of a new file. I need the variables in the included file to be resolved so that the values are populated correctly.
To demo imagine these files:
main.php
$someVar = "someValue";
$fileText = include "aTemplate.php";
$newFileName = 'someFile.php';
if (file_put_contents($newFileName, $fileText) !== false) {
echo "File created (" . basename($newFileName) . ")";
} else {
echo "not created";
}
aTemplate.php
<?php
return
'<!doctype html>
<html lang="en">
<head>
<title><?php echo $someVar; ?></title>
</head>
</html>'
?>
What is currently happening is that the variables stay unresolved and hold no value so in the created html file the title is:
<title></title>
Instead of
<title>someValue</title>
How can I change the 'aTemplate.php' file to resolve the properties set in 'main.php'?
Just use this at your aTemplate.php:
<?php
return '<!doctype html>
<html lang="en">
<head>
<title>'. $someVar .'</title>
</head>
</html>';
?>
There are a couple of problems with your template, firstly as you have the HTML in single quotes, this won't do any of the string substitutions. Secondly, your trying to do a PHP echo whilst in HTML in PHP. I've used Heredoc to enclose the HTML as it allows any sorts of quotes and will also do the replacements.
The substitution of the value is just replaced by adding $someVar directly into the string.
So aTemplate.php becomes...
<?php
return <<< HTML
<!doctype html>
<html lang="en">
<head>
<title>$someVar</title>
</head>
</html>
HTML;
You should echo those string in page instead of return command.
The keyword return is used inside a function while your file is not a function. The browser simply puts what's inside include file has to offer. In you case it is HTML string which should be outputted using echo command.
Also the server executes code in top to bottom and left to right. Thus the variable $someVar will be accessed in aTemplate.php file.
Use below code instead to work
main.php
$someVar = "someValue";
$file = 'aTemplate.php';
// Open the file to get existing content
$fileText = include "aTemplate.php";
$newFileName = 'someFile.php';
// Write the contents back to the new file
if (file_put_contents($newFileName, $fileText) !== false)
{
echo "File created (" . basename($newFileName) . ")"; }
else {
echo "not created";
}
aTemplate.php
<!doctype html> <html lang="en"><head>
<title><?php echo $someVar;?></title>
</head>
</html>
I'm trying to pass the php variable $shareURL = "someURL"; from the parent page of test.php into the included file of commentTest.php. Is this possible? If yes, please help.
Parent File = Test.php
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<?php
$shareURL = "someURL";
echo "$shareURL";
include "http://domainName.net/assets/includes/commentTest.php";
?>
</body>
</html>
PHP Included File = commentTest.php
<?PHP
echo "<div class='fb-comments' data-href='$shareURL' data-num-posts='5' data-width='100%'></div>";
?>
HTML Output Source
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
someURL<div class='fb-comments' data-href='' data-num-posts='5' data-width='100%'></div></body>
</html>
Change your Test.php to this:
include "/assets/includes/commentTest.php";
Thanks everyone!
Your comments and answers helped me find the solution I needed.
$root = dirname(__FILE__);
include "$root/assets/includes/commentTest.php";
Apparently my root is here /var/www/html instead of right after the TLD in the URL.
I have a php code that will extract and retrieve all the images in a website. How do I modify the code so that the dimensions(width and height) of the images are shown as well?
This is the php coding:
<?php
$page_title = "MiniCrawler";
?>
<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title><?php print($page_title) ?></title>
</head>
<body>
<?php
ini_set('display errors',1);
error_reporting(E_ALL|E_STRICT);
Include simple_html_dom.php.
include_once ('simple_html_dom.php');
// Add the url of the site you want to scrape.
$target_url = "http://www.alibaba.com/";
// Let simple_html_dom do its magic:
$html = new simple_html_dom();
$html->load_file($target_url);
// Loop through the page and find everything in the HTML that begins with 'img'
foreach($html->find('img') as $link){
echo $link->src."<br />";
echo '<img src ="'. $link->src.'"><br />';
}
?>
</body>
</html>
Thanks
First you would have to check, if the $link->src string already has the domain name at the beginning:
<?php
if(substr($link->src, 0, 4) == "http"){
// url already complete
$path = $link->src;
}else if(substr($link->src, 0, 1) == "/"){
// path starts absolute
$path = $target_url . $link->src;
}else{
// path starts relative -> http://stackoverflow.com/questions/4444475/transfrom-relative-path-into-absolute-url-using-php
}
?>
Then: Request the files dimensions via the getimagesize() function.
<?php
list($width, $height, $type, $attr) = getimagesize($path);
echo '<img src ="'. $link->src.'" width="' . $width . '" height="' . $height . '"><br />';
?>
Whether I enter the value for bug id or not ..in both conditions the code between php tags is displayed as output. Can someone help me to find out the reason.
Code is given below:
html file-------------------------------------------------------------
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Bug Report</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<h2>Bug Report</h2>
<form action="test.php" method="post" >
<p>Bug ID:<input type="text" name="bugid" size="20" /></p>
<p><input type="submit" value="Record Bug" /></p>
</form>
</body>
</html>
php file--------------------------------------------------
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Record Bug</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
$bugid=$_POST["bugid"];
echo $bugid;
if (empty($bugid))
{
echo "<p>You must enter the Bug ID to record the bug.</p>";
}
else
{
echo"<p>good</p>";
}
?>
</body>
</html>
If you're getting PHP code in the output, then your webserver isn't running that page/script through the PHP interpreter. Generally, that's because you've put the code into a .html file, which is not treated as PHP by default.
Either rename the file to whatever.php, or reconfigure your webserver to treat .html files as PHP scripts.
check that php is working or not for that write the code <?php phpinfo(); ?> and if have manually installed php apache and getting problem try wamp server
your code is widely open for sql-injunction to make it secure use
public function mysql_prep( $value ) {
$magic_quotes_active = get_magic_quotes_gpc();
$new_enough_php = function_exists( "mysql_real_escape_string" ); // i.e. PHP >= v4.3.0
if( $new_enough_php ) { // PHP v4.3.0 or higher
// undo any magic quote effects so mysql_real_escape_string can do the work
if( $magic_quotes_active ) { $value = stripslashes( $value ); }
$value = mysql_real_escape_string( $value );
} else { // before PHP v4.3.0
// if magic quotes aren't already on then add slashes manually
if( !$magic_quotes_active ) { $value = addslashes( $value ); }
// if magic quotes are active, then the slashes already exist
}
return $value;
}
Check whether php is running or not in your machine. Save the below code as test.php and run it through
<?php
phpinfo();
?>
In that case you have to run on that Server which support PHP like Xampp or Wamp and also extension of the file should be .php
I have an upload script that write a index.html file, I modified it to mail me the results, however the point to the root, since the email isn't in the root, the image doesn't load.
How do I append the code to add "http://www.home.html/uploaded" prior to the ". $value ." so that the images show up in the email.
Here is portion of PHP that assigns the images to a $result:
// Process value of Imagedata field, this is JPEG-files array
foreach ($_FILES[Imagedata][name] as $key => $value)
{
$uploadfile = $destination_dir . basename($_FILES[Imagedata][name][$key]);
if (move_uploaded_file($_FILES['Imagedata']['tmp_name'][$key], $uploadfile))
{
$result .= "File uploaded: <a href='". $value . "'>" . $value . "</a><br>";
}
}
//
$result .= "<br>";
Here is what I'm now receiving in the email, :
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Upload results</title>
</head>
<body>
AdditionalStringVariable: pass additional data here<br><a>
href='gallery_grannylovesthis_l.jpg'><img border = '0'
src='QIU_thumb_gallery_grannylovesthis_l.jpg'/></a><br><br><br>File uploaded: <a
href='gallery_grannylovesthis_l.jpg'>gallery_grannylovesthis_l.jpg</a><br><br>
GlobalControlData:
PHOTO_VISIBILITY : 2<br>
GlobalControlData:
PHOTO_DESCR : Requiredtest<br>
GlobalControlData:
PHOTO_TITLE : Requiredtest<br><br>gallery_grannylovesthis_l.png<br> control: , value: <br>
</body>
</html>
Thanks in advance for any guidance...I have a feeling it's something simple.
Like this:
<a href='http://www.home.html/uploaded/". $value . "'>"
Your code has a malformed tag:
<a>
href='gallery_grannylovesthis_l.jpg'><img border = '0'
It should be like this:
<a href='gallery_grannylovesthis_l.jpg'><img border = '0'
Notice on yours you have href (you added a > when there should not be one)