Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.