Hello I am working on simple video script where I need to do the following:
I need to check if Variable Source is empty (if it's not empty echo $source, but if it is empty proceed to check other variable below)
if Variable Embed is set, if it is set (echo $embed), but if it is empty do
echo $image
Basically I have setup system for Videos that can load either from Youtube Video with iframe, either with Embed from all kinds of other pages
but if Both of this fields are empty I need to show just image that will be set from URL
You can use an elseif-statement.
if(isset($source) && $source) {
echo $source;
} elseif(isset($embed) && $embed) {
echo $embed;
} else {
echo $image;
}
Related
I want to ask you guys about my code in my php update form.
I use unlink($file_Path) to Remove my image file in my folder & my server and that work fine!
So I wonder when using "unlink($file_Path)" to removing an image, In my php page it show me an "Image File Icon " when there was no picture (The image file was removed) But it show me like that (Image file Icon) Because, I though It still has a some value (my value = "../filename.jpg")
so I put "value=" "/" (None Value to Reset a Value)
example :
<input type="hidden" name="newSubimage1" value=""/>
and that work fine when I use with "!empty($ro.."
example :
if (isset($row['subimage1']) && !empty($row['subimage1']))
{
echo "<img src='../images/images_products/".$row['subimage1']."'>";
} else {
echo "No Image Here"; }
`
to not show an "Image File Icon"
Is that a correct way ? that I used to Removing file / Not display an Image File Icon or you has any easy way or the best way that you want to suggest me.
thanks
$image_file_ext = array('jpg', 'png', 'bmp');
$file_ext = pathinfo($row['subimage1'],PATHINFO_EXTENSION);
if (isset($row['subimage1']) && !empty($row['subimage1']) && in_array($file_ext, $image_file_ext))
{
echo "<img src='../images/images_products/".$row['subimage1']."'>";
} else {
echo "No Image Here";
}
I am extracting image metadata using php. The logic of my below code is that if the user uploads the default file with metadata(UserComment)=ASCIIsd11, he/she will get an error.
<?php
$exif_s = exif_read_data('e42889ed00.jpg');
$phtchk = $exif_s["UserComment"];
print $phtchk;
print strcmp($phtchk, "ASCIIsd11");
if(strcmp($phtchk, "ASCIIsd11") == 0){ echo "You have not uploaded your own photo"; exit;}
else
{
echo"You have uploaded it.";
}
?>
print $phtchk; returns ASCIIsd11
print strcmp($phtchk, "ASCIIsd11"); returns -1
and the last echo statement "You have uploaded it" is printed. Actually I am expecting strcmp() to return 0. Kindly help.
Do var_dump(phtchk); instead of print $phtchk;
Perhaps you don't see some extra-chars (eg: \n).
If it concerns the collation, you should see:
UTF-8 characters not displaying properly from JPEG IPTC data in PHP
I am trying to echo $_POST['admin_name']; on next page but it's not working.
How can I do this?
if(($a_name==$adminname)&&($pass_word==$pass)) {
if($a_name=="goher") {
$_POST['admin_name']=$a_name;
echo "<script>window.location='home.php'</script>";
}
else {
$_POST['admin_name']=$a_name;
echo "<script>window.location='upload.php'</script>";
}
}
else {
echo "<script>window.location='signin.php?msg=Try Again'</script>";
}
Assigning something to $_POST does not make the data available on some other page (you don't even POST in your case).
I think what you want is $_SESSION - when using sessions the data you stored there will be available on subsequent page loads (assuming you always call session_start()).
I am trying to get value with ajax and the values are in form of string, but the problem is when I'm trying to use a condition of if value empty then return this or else do that
My code is
if (empty($title) || empty($thumbnail) || empty($link))
{
echo "404";
}
else
{
some custom line
}
My problem is that a 404 is returned even if the value of any one of them (title, thumbnail, or link) is not empty. Can any one point me where I am wrong?
Here's how I am getting value from ajax:
$title = mysql_real_escape_string($_REQUEST['title']);
$thumbnail = mysql_real_escape_string($_REQUEST['thumbnail']);
$link = mysql_real_escape_string($_REQUEST['link']);
First of all I suggest you to do not use empty, cause it got some specific behave.
Second: I don't get why you are using mysql_real_escape_string, you have to query a database?
Moreover i guess you (as #havelock pointed out) wanted to get a 404 if none of that values are set up.
I'm for this:
if($title && $thumbnail && $link){
//all fine..
}
else 404
So after I store a pathname of an image file in mysql php, I am having difficulty retrieving that image to display. In other words, when I do an "inspect element" the "src" value is set. However, the image doesnt display and all that is left is a square box on the page. I tried using a default profile picture that is already set for the user, just to check if its a php assigning value problem. But its not. I also checked the file contents physically and all the files are uploaded fine. The only problem is getting it to display.
Here's how I do it.
Php for checking file upload
error_reporting(E_ALL);
if($_SERVER["REQUEST_METHOD"]=="POST"&&isset($_POST["savePersonalInfo"]))
{
if(isset($_FILES["ppFile"]))
{
$name=$_FILES["ppFile"]["name"];
$tempName=$_FILES["ppFile"]["tmp_name"];
$size=$_FILES["ppFile"]["size"];
$type=$_FILES["ppFile"]["type"];
if(($type=="image/jpg"||$type=="image/jpeg"||$type=="image/pjpeg")&&( ($size>0&&$size<=4000000000))
{
$dir="C:/xampp/htdocs/hcUsers/".$_SESSION['pin']."/profilePictures";
$realPath=$dir."/".$name;
if(is_dir($dir))
{
move_uploaded_file($tempName,$realPath);
$_SESSION["ppPath"]=$realPath;
$fileQuery="UPDATE `current users` SET `ppPath`='$realPath' WHERE `id`='".$_SESSION['pin']."' " ;
checkConnect(mysql_query($fileQuery),"query of $fileQuery");
}
else
{
mkdir($dir,0777,true);
move_uploaded_file($tempName, $realPath);
$_SESSION["ppPath"]=$realPath;
$fileQuery="UPDATE `current users` SET `ppPath`='$realPath' WHERE `id`='".$_SESSION['pin']."' " ;
checkConnect(mysql_query($fileQuery),"query of $fileQuery");
}
}
else
{
print "Error".$_FILES["ppFile"]["error"];
}
}
?>
Php for retrieving the image pathname and displaying the image
<?php
session_start();
connectDatabase();
$query="SELECT * FROM `current users` WHERE `email`='".$_SESSION['email']."' AND ` `password`='".$_SESSION['password']."' ";
$result=mysql_query($query);
checkConnect($result,"query of $query");
$row=mysql_fetch_assoc($result);
$_SESSION["pin"]=$row["id"];
$imgPath="http://www.metalmusicarchives.com/images/covers/avariel-no-end-in-sight(demo)-20110719103608.jpg";
if($row["ppPath"]!="")
{
$imgPath=$row["ppPath"];
$_SESSION["ppPath"]=$imgPath;
}
?>
<p><img src="<?php echo $imgPath ?>" alt="" type="image/jpeg" class="profilePic" >
In the end the 'src' value is set but the image won't display.
Please help.
This is a part of your code:
$dir="C:/xampp/htdocs/hcUsers/".$_SESSION['pin']."/profilePictures";
$realPath=$dir."/".$name;
if(is_dir($dir))
{
move_uploaded_file($tempName,$realPath);
$_SESSION["ppPath"]=$realPath;
$fileQuery="UPDATE `current users` SET `ppPath`='$realPath' WHERE `id`='".$_SESSION['pin']."' " ;
This way, when retreiving ppPath from the database and trying to display it in a browser, the src of the image will point to C:/xampp/etc. That won't work, since your visitors don't have access to that directory. Neither do you, from a browser's perspective. Change it to a relative URL.
Furthermore I see a lot of duplicate code and you're abusing session variables, but that's offtopic.