Zubrag.com
April 25, 2018, 12:54:27 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: file smart download script for random file names  (Read 3568 times)
Alex-B
Newbie
*
Posts: 3


« on: July 23, 2009, 02:06:20 AM »

I will explain myself:

I have created table in MySQL called it “files” that contains names of the original files on my server and the random names assigned to each of this files: (Not sure if this is a right way)

IDOriginalFileNameRandomFileName
001Purchase-Order-Template.xls file-purchaseorder
0025-year-financial-plan-manufact.xlsfile-businesplan
002Beverage-StockTake-Template.xlsfile-beveragestocktake

all original files are in the folder called /files/ on my server.

I have also used some PHP script to enable users to download each file and named it download.php

This is the script that I have used: (again not sure because I do not know much about PHP)

<?php
// Connects to your Database
mysql_connect("serveraddress", "username", "password") or die(mysql_error());
mysql_select_db("username") or die(mysql_error());
$data = mysql_query("SELECT * FROM files")
or die(mysql_error());
//get the original file name
//where your $_GET['urlid'] =
//RandomFileName and set it equal
//to $saveName

//this will be equal to the
//original file name you get from
//the db
$saveName = "OriginalFileName";

$fileName = $_GET['urlid'];
Header("Content-type: application/xls");
Header("Content-Disposition: attachment; filename=$saveName");
readfile("$fileName");

?>

Now when I am placing a simple link on the page were user can download the file from in this format:

Download Now

when you click on the Download Now link the process starts running but you cannot get the actual file at the end for some reason.

I think I do have an error some ware in the script but cannot figure it out. could anyone please help me a little and could you actually use the names that I have provided so I can see what goes were?

Thanks in advance

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC