Jump to content

PHP Code inside PHP Code !!


manalnor

Recommended Posts

Hello friends,

 

if i've the following code ( link protected code )

 

<a href="<?php linklokurl('download.zip',0,1,0); ?>">Download Here</a>

 

and i've another php coder

 

 

<?php
$filename = "x.txt";
if (file_exists($filename)) {
$contents = file_get_contents($filename);
echo '' . htmlspecialchars($contents) . '';
}
else {
echo 'No Files';
}
?>

 

i want to write this as following but sure it has some error

- will replce the file download.zip with . htmlspecialchars($contents) .

 

 

 

<?php
$filename = "x.txt";
if (file_exists($filename)) {
$contents = file_get_contents($filename);
echo "<a href="<?php linklokurl('. htmlspecialchars($contents) .',0,1,0); ?>">Download Here</a>";
}
else {
echo 'No Files';
}
?>

 

looks complex 3 php codes within each other  :'( can someone kindly write the last code with respect to php rules

Link to comment
https://forums.phpfreaks.com/topic/207274-php-code-inside-php-code/
Share on other sites

file_get_contents() gets the contents of the file in question. It won't make it available for download.

I'm mystified about what you're exactly trying to achieve here.

 

my idea is very simple ..

1- make text file where i store the name of downlaodble file (download.zip)

 

2- when file do exsit then it will show the download link and if not then it will show the " No Files "

 

and that one fixed , thank you all.

 

but the second part is how to protect the link  :D

i found linklok is good but i'm trying to integrate

 

<a href="<?php linklokurl('download.zip',0,1,0); ?>">Download Here</a>

 

with

 

<?php
$filename = "x.txt";
if (file_exists($filename)) {
$contents = file_get_contents($filename);
echo '' . htmlspecialchars($contents) . '';
}
else {
echo 'No Files';
}
?>

 

but with replce of download.zip to the content of the text file which should be  . htmlspecialchars($contents) .

 

 

so my problebm how to write this

 

echo "<a href="<?php linklokurl('. htmlspecialchars($contents) .',0,1,0); ?>">Download Here</a>";

 

indeed it shows error cause can't write <?php inside echo () and also . htmlspecialchars($contents) . can't be ..

 

so i need someone to rewrite it.

 

that is my point .. ::)

From what I can make out from your description, this should work.

 

<?php
$filename = "x.txt";
if (file_exists($filename)) {
  $contents = file_get_contents($filename);
  
  if (!empty($contents)) {
    echo '<a href="'. linklokurl(htmlspecialchars($contents), 0, 1, 0)) .'">Download Here</a>';
  }
  else {
    trigger_error('The file <strong>'. $filename .'</strong> is empty.', E_USER_WARNING);
  }
}
else {
  trigger_error('The file <strong>'. $filename .'</strong> does not exist.', E_USER_ERROR);
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.