manalnor Posted July 9, 2010 Share Posted July 9, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/207274-php-code-inside-php-code/ Share on other sites More sharing options...
Wolphie Posted July 9, 2010 Share Posted July 9, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/207274-php-code-inside-php-code/#findComment-1083745 Share on other sites More sharing options...
manalnor Posted July 9, 2010 Author Share Posted July 9, 2010 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 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 .. Quote Link to comment https://forums.phpfreaks.com/topic/207274-php-code-inside-php-code/#findComment-1083747 Share on other sites More sharing options...
Wolphie Posted July 9, 2010 Share Posted July 9, 2010 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/207274-php-code-inside-php-code/#findComment-1083753 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.