Forum Moderators: open

Message Too Old, No Replies

Table for MySQL

Need a little help with Table for MySQL

         

AlexB77

3:11 pm on Jul 23, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi to all,

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

arlo

7:20 pm on Sep 10, 2009 (gmt 0)

10+ Year Member



You can try an <iframe></iframe>, this will let you load 2 different pages on one browser. When people click on a file you will send them to dlfile.php?urlid=excel-book (the page with the iframes)

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.

AlexB77

11:42 am on Sep 16, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



You are a very big help. I do not know how to thank you.

Thanks a lot.

Alex

AlexB77

12:38 pm on Sep 16, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



HI again,

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?

arlo

6:15 pm on Sep 16, 2009 (gmt 0)

10+ Year Member



i am sorry, here is the revised code for line 38:

echo '<a href="'.basename($file_path).'">Click here if download did not start after 5 seconds</a> ';

If you have more errors just let me know...i never tested this code, i just typed it out here. =/

AlexB77

7:47 pm on Sep 16, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



it has worked partly, but still has an error.

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

arlo

7:50 pm on Sep 16, 2009 (gmt 0)

10+ Year Member



try this:

echo '<a href="'.$file_path.'">Click here if download did not start after 5 seconds</a> ';
This 36 message thread spans 2 pages: 36