I am trying to run one of the two files on my site using if file exist and readfile functions.
When I give the file path in readfile() it runs properly.
But when I use same file path into if file exist() it says "file does not exist".
=================
It returns error "file does not exist"
<?php
$filename = '{SITE_URL}templates/{TPL_NAME}/sidebars/{NODE_ID}.html';

if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
=====================
It runs properly .....
<?php
readfile("{SITE_URL}templates/{TPL_NAME}/sidebars/{NODE_ID}.html");
?>
=========================
It does not work at all .....
<?php
IF(file_exists("{SITE_URL}templates/{TPL_NAME}/sidebars/{NODE_ID}" . ".html"))
{
readfile("{SITE_URL}templates/{TPL_NAME}/sidebars/{NODE_ID}.html");
}
?>
====================
Though this file path contains memory variables still works fine in readfile(). Actual file path is http://eshop11.com/templates/version4/sidebars/268.html

I have just viewed some where that "if file exist" function works only in current directory while readfile() can work from any where.
Any suggestions/guidance please.

I am trying to run one of the two files on my site using if file exist and readfile functions.
When I give the file path in readfile() it runs properly.
But when I use same file path into if file exist() it says "file does not exist".
=================
It returns error "file does not exist"
<?php
$filename = '{SITE_URL}templates/{TPL_NAME}/sidebars/{NODE_ID}.html';

if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
=====================
It runs properly .....
<?php
readfile("{SITE_URL}templates/{TPL_NAME}/sidebars/{NODE_ID}.html");
?>
=========================
It does not work at all .....
<?php
IF(file_exists("{SITE_URL}templates/{TPL_NAME}/sidebars/{NODE_ID}" . ".html"))
{
readfile("{SITE_URL}templates/{TPL_NAME}/sidebars/{NODE_ID}.html");
}
?>
====================
Though this file path contains memory variables still works fine in readfile(). Actual file path is http://eshop11.com/templates/version4/sidebars/268.html

I have just viewed some where that "if file exist" function works only in current directory while readfile() can work from any where.
Any suggestions/guidance please.

If the php file is in the top directory, then there should be no need for the {SITE_URL}, so leave that part out on both examples.

Also, PLEASE wrap your code in code tags before posting. It makes things easier to see, and it makes users happier to help you. :)

Member Avatar for rajarajan2017

Give the path directly and check it once.

i have small upload script maybe it can help u to understand what mistake u got

<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 200000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("gallery/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. "; //here is the code u want
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "gallery/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "gallery/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>

@rajarajan07 i guess its very old post.. xD

Member Avatar for rajarajan2017

Thanks for your alert. Already I have posted in many thread dont make others to reply for old thread. Anyway its happened again! Very new members of dani replied to some of the old posts without the awareness.

@DarkBerzer

still nice for people finding this post with google to find some more answers

what about cr8ing new post? :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.