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:
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/.
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:
<?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:
<a href="http://www._____.com/download.php?urlid=file-purchaseorder" target="_blank" class="shadow">Download Now</a>
when you click on the Download Now link the process starts running but you cannot get the actual file at the end.
I think I do have an error some ware in the script but cannot figure it out. could you 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
My SQL and PHP code problems
Moderator: General Moderators
Re: My SQL and PHP code problems
i hope problem with following line.
$saveName should be the file name which downloading user will get [like download.xls]
$fileName should be the original file which exists in your server[if file exist in different folder mention filename with root path].
buy you given it wrong in your coding.. plz change this and try..
Header("Content-Disposition: attachment; filename=$saveName");
readfile("$fileName");
$saveName should be the file name which downloading user will get [like download.xls]
$fileName should be the original file which exists in your server[if file exist in different folder mention filename with root path].
buy you given it wrong in your coding.. plz change this and try..
Re: My SQL and PHP code problems
Thanks for you reply !!
But I have more than 1 file in the /files/ folder. and therefore I needed to assign the random names to this files. But how to do it I do not have any idea.
Thanks again
But I have more than 1 file in the /files/ folder. and therefore I needed to assign the random names to this files. But how to do it I do not have any idea.
Thanks again