Forum Moderators: open
Need a little help with table for MySQL.
I need to create a table that will have originale file name - that is lokated on my server in folder called "files" and need also to have a random name of the same file.
So that it looks like this one bellow
/files/excel-book.xls(real Name of the file) - excelbook
/files/macro-book.xls(real Name of the file) - macrobook
/files/codec-book.xls(real Name of the file) - codecbook
the reason I need it is to have a "download now" links on the
other pages of the site that will pint to the random name so once user will click on it than the /download.php should idealy triger the download of the file with this particular randome name (ex. <a href="http://www._____.com/download.php?urlid=excelbook">Download Now</a> than it should open /files/excel-book.xls this file)
Thanks to all for your help and thanks to this forum as well
Content for dlfile.php:
<iframe src="download.php?urlid=<?=$_GET['urlid']?>"></iframe>
<iframe src="dl_click.php?urlid=<?=$_GET['urlid']?>"></iframe>
With this method you will need to also create the php file "dl_click.php", but it is easy. dl_click.php is very similar to download.php.
Copy download.php and replace:
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file_path));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file_path));
ob_clean();
flush();
readfile($file_path);
with this:
<a href="<?=basename($file_path)?>">Click here if download did not start after 5 seconds</a>
I hope this helps you accomplish what you need.
I have a little problem
Parse error: syntax error, unexpected '<' in /home/fhlinux199/s/spreadsheet123.com/user/htdocs/dl_click.php on line 38
Now on line 38 in my code I have this link: <a href="<?=basename($file_path)?>">Click here if download did not start after 5 seconds</a>.
This is how it looks like:
# Query for file info
$res = mysql_query("SELECT * FROM `Files` WHERE `file_display_name`='".$file_code."'") or die ( mysql_error() );
# If query is empty, there is a bad code name
# This catches possible hacking attempt.
if( mysql_num_rows($res) == 0 )
{
echo 'There will be no hacking on this website! ';
exit();
}
# Save file info into an array called "$info"
$info = mysql_fetch_assoc($res);
# File path is below
$file_path = $path_to_file_directory.$info['file_name'];
# Now push the download through the browser
# There is more than 1 way to do this.
if (file_exists($file_path)) {
<a href="<?=basename($file_path)?>">Click here if download did not start after 5 seconds</a>
exit;
}
Do you know what may cause a problem there?
now it is giving me a link as it should have, but the link points to the wrong direction.
[mysite.com...] when it should point to [mysite.com...] or at least to [mysite.com...]
so it takes /files/ out of it for some reason