homepage Welcome to WebmasterWorld Guest from 54.197.189.108
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
mysql upload to table, and upload to server
tr8er8




msg:3578591
 7:42 am on Feb 19, 2008 (gmt 0)

Hi I have a page that uploads files to a folder on my server. It works fine, it checks the file types, and if it exists already and all that good stuff, but I want it to also upload to my database. I'm mostly going to be uploading .zip and .rar files, but I'm not sure how to make them get uploaded to my database, or if it's just a link. I'm not sure. But how would I upload a file from my computer and store it in a database, as well as upload it to my server?

 

phparion




msg:3578713
 11:58 am on Feb 19, 2008 (gmt 0)

if you are uploading the file to your server then you don't need to upload the full file to the mysql database. you just need to mention its link in the mysql table e.g

you download backup1.zip in /uploads/ then in mysql table where you store the upload information you can store its name like /uploads/backup1.zip

then just link it in your pages for downloading.

there are different issues which you may be considering e.g how to hide the actual download link so that people cannot hotlink your files or get the uploads directory path.. you can do it with php easily then by composing the download link and using HEADER() to redirect to the file or some other similar trick.

tr8er8




msg:3579053
 6:40 pm on Feb 19, 2008 (gmt 0)

Yeh I want to have the file thing like microsoft has, you just get the file without knowing the path to all the downloads, is there any way I can do that?

jatar_k




msg:3579238
 8:48 pm on Feb 19, 2008 (gmt 0)

you would use a downloader script

the link would look something like

www.example.com/download.php?fileid=12345

where 12345 is the id from the row in mysql

the script would get the path and all info about the file from the db by using the id passed in $_GET

then it puts together the headers and forces the download

tr8er8




msg:3579281
 9:12 pm on Feb 19, 2008 (gmt 0)

Ok cool thanks, I'm not sure on how to like make it a new ID by itself everytime I put a new row in the database. Like how would I make it do it by itself?

jatar_k




msg:3579521
 1:00 am on Feb 20, 2008 (gmt 0)

have your id column set to auto increment, this will ensure that it is unique

it will increment each time by itself if you just use an empty set of quotes on INSERT

tr8er8




msg:3579613
 3:00 am on Feb 20, 2008 (gmt 0)

Alright yeh I just figured it out.

phparion




msg:3579693
 5:20 am on Feb 20, 2008 (gmt 0)

You can also generate a one-time temporary download links for people, if you email the link for downloading rather than offering on-the-fly downloading.

For that you might use generate a timestamp based unique number for the user and store it in a download-queue table. email the link,as jatar_k told you. When the visitor visits the link, check if the unique number embedded in the link exisits, if it does then send the visitor to the download page and remove the unique number / download request number from the table.

if the number doesn't exist simply show the requist expires or wrong request number error.

tr8er8




msg:3579722
 5:43 am on Feb 20, 2008 (gmt 0)

How would I like display the page, like jatar_k said. Like if I had the id, how would I do download.php?id=1 or whatever.

phparion




msg:3579730
 6:04 am on Feb 20, 2008 (gmt 0)

OMG! you got to learn basic php-mysql concepts...

make a download.php page that displays nothing... connect to mysql, select downloadlink from table where id=$_REQUEST['id'] and header() ...

tr8er8




msg:3579731
 6:13 am on Feb 20, 2008 (gmt 0)

doh! yeh imma dummy lol I just know like little about forms and like emailing forms, thats about all I can do by myself. Ive been trying to learn this stuff on php.net and stuff but its confusing to me. sorry =[
btw whats the downloadlink thing you said?

tr8er8




msg:3579732
 6:14 am on Feb 20, 2008 (gmt 0)

ohh nvm I see.

what do I put as the header and stuff, I keep seeing stuff about header() but idk what it is.

phparion




msg:3579738
 6:51 am on Feb 20, 2008 (gmt 0)

www.w3schools.com is a very good place to start learning php. Also google php-mysql tutorial and you will get a website with very similar name, follow that...

You will face lots of problems if your base is not firm and you are completing tasks with quick helps.. so I will strongly suggest you firming your base by learning php properly.

header("location: http://example.com/uploads/file.zip");

this is how it works

tr8er8




msg:3579765
 8:07 am on Feb 20, 2008 (gmt 0)

Ok thanks I got it to work. Now I googled and looked in on how to hide the actual url, but I'm still not sure on how to do that.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved