Forum Moderators: open

Message Too Old, No Replies

My SQL problems

Need to create a table with file names and file random names

         

AlexB77

6:48 pm on Jul 21, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



Can anybody help me to create a table for My SQL DB that need to have a file name (ex. budget-template.xls) and assigned random name of the same file (ex. file-personalbudget) and also explain to me the way that this table need to be uploaded to the MySQL DB.

Second question is: what if the original files are in the folder (ex. /files/budget-template.xls)and there is more than one file in the same folder?

and at last: how do I need to make all this files downloadable with php script? so that I can use only a random names of the original files.

Thanks to all.

Adastra

8:25 am on Jul 22, 2009 (gmt 0)

10+ Year Member



Your message isn't very clear.
To create a table in mysql use phpmyadmin this can be downloaded from www. phpmyadmin.net

The rest of your question i don't understand. Can you explain what you are trying to do?

AlexB77

2:15 pm on Jul 22, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi thanks for your reply!

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