0

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.

5
Contributors
8
Replies
10
Views
7 Years
Discussion Span
Last Post by DarkBerzerk™
0

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. :)

0

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";
  }
?>

Edited by DarkBerzerk™: n/a

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.