Jump to content

HELP! How to download a file from your html website. Also another thing about html coding/databases

mkessler9

Hello so I have 2 questions.

 

Problem 1.

Ok so I'm fairly new to making websites. What I've been trying to do is set up my website so that if I click on a link it will download my file. Say a program that I made(just as example purposes, I have no idea how to code programs as I am new to this). I have setup the link and where to access the file on my web server when the link is clicked but when I click on the link on my web site it loads a new page and says 404. How do I fix this problem? As far as the directory of the file I know that is correct. But I'm not entirely sure that the code to tell the browser to download the file is correct. So could someone please post the code to tell the browser to download the specified file? Thanks.

 

Problem 2.

So I've also been trying to make a login page so that me and other users can access certain things or edit the website. I have watched many tutorials and have since then installed mqsql and phpmyadmin. That works and I can view the localhost file from phpmyadmin. I also have phpmyadmin in the correct directory and I can access it and attempt to setup my data base for the user login(I have all the files for the webpage itself like the box for username login and pass). But my problem is when I follow exactly how the people on youtube say to setup the database I still can't get it to work. Could someone please post in the chat exact instructions on how to create the database and how to make my website be able to access it? Preferably in text because I've already watched a ton of youtube videos on it.

 

Thanks in advance.

 

Also sorry if this should be under the programming page. I just figured since I'm having an issue that it should be under troubleshooting.

Gaming rig- Cpu- Amd 9590, 16gbs of G Skill Ram, Gpu- GTX 760 windforce 3 edition 2gb. A Thermaltake water 2.0 water cooler for my cpu. Keyboard- Thermaltake Posieden , Case- 750D, Mobo Asus 990fx R2.0. 24 inch Dell LED monitor

Link to comment
Share on other sites

Link to post
Share on other sites

@mkessler9

I've moved your topic to the programming section, you're more likely

to get help here I think. Also, it would help if you posted the relevant

parts of your code for others to review and figure out what's going

wrong. :)

BUILD LOGS: HELIOS - Latest Update: 2015-SEP-06 ::: ZEUS - BOTW 2013-JUN-28 ::: APOLLO - Complete: 2014-MAY-10
OTHER STUFF: Cable Lacing Tutorial ::: What Is ZFS? ::: mincss Primer ::: LSI RAID Card Flashing Tutorial
FORUM INFO: Community Standards ::: The Moderating Team ::: 10TB+ Storage Showoff Topic

Link to comment
Share on other sites

Link to post
Share on other sites

Problem 1

[...] As far as the directory of the file I know that is correct. [...]

if it's a 404, the directory is wrong, doublecheck it

the "code for downloading a file" can just be a link to the file, if the file is not a webpage

so, if you want to download file.zip which sits in the same directory as download.html, that page will just contain

<A href = "file.zip" > download! </A>

if you post the code, or the urls, we can help

 

 

Problem 2

Could someone please post in the chat exact instructions on how to create the database and how to make my website be able to access it?

creating the database in phpmyadmin should be pretty intuitive, there should be a "create database" big button or something similar

to access it from your website you will need to use some functions to talk with it, such as mysqli for PHP

but you will need to know how to program and how to query a database, if you don't then this is not the place where to learn all of that

Link to comment
Share on other sites

Link to post
Share on other sites

@mkessler9

I've moved your topic to the programming section, you're more likely

to get help here I think. Also, it would help if you posted the relevant

parts of your code for others to review and figure out what's going

wrong. :)

Ok. Thanks :D

Gaming rig- Cpu- Amd 9590, 16gbs of G Skill Ram, Gpu- GTX 760 windforce 3 edition 2gb. A Thermaltake water 2.0 water cooler for my cpu. Keyboard- Thermaltake Posieden , Case- 750D, Mobo Asus 990fx R2.0. 24 inch Dell LED monitor

Link to comment
Share on other sites

Link to post
Share on other sites

if it's a 404, the directory is wrong, doublecheck it

the "code for downloading a file" can just be a link to the file, if the file is not a webpage

so, if you want to download file.zip which sits in the same directory as download.html, that page will just contain

<A href = "file.zip" > download! </A>

if you post the code, or the urls, we can help

 

 

creating the database in phpmyadmin should be pretty intuitive, there should be a "create database" big button or something similar

to access it from your website you will need to use some functions to talk with it, such as mysqli for PHP

but you will need to know how to program and how to query a database, if you don't then this is not the place where to learn all of that

Ok. I got the download to work. The path was correct but it wasn't in a zip/rar file. So why do I need to make it a rar file before I can download it? Because I've been on plenty of websites where I can just download the program without it being in a zip file. Or is it just the way you have to do it when coding with html? 

 

if it's a 404, the directory is wrong, doublecheck it

the "code for downloading a file" can just be a link to the file, if the file is not a webpage

so, if you want to download file.zip which sits in the same directory as download.html, that page will just contain

<A href = "file.zip" > download! </A>

if you post the code, or the urls, we can help

 

 

creating the database in phpmyadmin should be pretty intuitive, there should be a "create database" big button or something similar

to access it from your website you will need to use some functions to talk with it, such as mysqli for PHP

but you will need to know how to program and how to query a database, if you don't then this is not the place where to learn all of that

And as far as creating the database goes I've done that but I'm not sure what to do next. Like how do I tell the code for a login page to visit the database?

Gaming rig- Cpu- Amd 9590, 16gbs of G Skill Ram, Gpu- GTX 760 windforce 3 edition 2gb. A Thermaltake water 2.0 water cooler for my cpu. Keyboard- Thermaltake Posieden , Case- 750D, Mobo Asus 990fx R2.0. 24 inch Dell LED monitor

Link to comment
Share on other sites

Link to post
Share on other sites

Ok. I got the download to work. The path was correct but it wasn't in a zip/rar file. So why do I need to make it a rar file before I can download it? Because I've been on plenty of websites where I can just download the program without it being in a zip file. Or is it just the way you have to do it when coding with html? 

 

And as far as creating the database goes I've done that but I'm not sure what to do next. Like how do I tell the code for a login page to visit the database?

the program doesn't have to be zip or rar

with this method, any file format that the browser can't visualize itself will be downloaded

 

in my previous post, i put a link to what you need for the database

google can give you code samples, if you ask him

Link to comment
Share on other sites

Link to post
Share on other sites

the program doesn't have to be zip or rar

with this method, any file format that the browser can't visualize itself will be downloaded

Then why when I have the code as this   <li><a href="downloads/vidtrial.mp4">Download</a></li> The link shows up and when I click I get a 404. The file is in a subfolder of the website which is why it says "downloads/vidtrial.mp4" btw.

Gaming rig- Cpu- Amd 9590, 16gbs of G Skill Ram, Gpu- GTX 760 windforce 3 edition 2gb. A Thermaltake water 2.0 water cooler for my cpu. Keyboard- Thermaltake Posieden , Case- 750D, Mobo Asus 990fx R2.0. 24 inch Dell LED monitor

Link to comment
Share on other sites

Link to post
Share on other sites

Then why when I have the code as this   <li><a href="downloads/movie.mp4">Download</a></li> The link shows up and when I click I get a 404. The file is in a subfolder of the website which is why it says "downloads/vidtrial.mp4" btw.

 

the program doesn't have to be zip or rar

with this method, any file format that the browser can't visualize itself will be downloaded

 

in my previous post, i put a link to what you need for the database

google can give you code samples, if you ask him

Wait never mind I just added the code

<?php
header('Content-disposition: attachment; filename=movie.mp4');
header('Content-type: video/mp4');
readfile('movie.mp4');
?>
to a php file and now it works.

Gaming rig- Cpu- Amd 9590, 16gbs of G Skill Ram, Gpu- GTX 760 windforce 3 edition 2gb. A Thermaltake water 2.0 water cooler for my cpu. Keyboard- Thermaltake Posieden , Case- 750D, Mobo Asus 990fx R2.0. 24 inch Dell LED monitor

Link to comment
Share on other sites

Link to post
Share on other sites

the program doesn't have to be zip or rar

with this method, any file format that the browser can't visualize itself will be downloaded

 

in my previous post, i put a link to what you need for the database

google can give you code samples, if you ask him

I have another question. How do I code the path to a file thats on another drive. Like say my website is on drive E and when I click on a link I want it to pull a file from drive Y. How would I do this? Would the path be "Y:NetworkStorage/movie.mp4" ?

Gaming rig- Cpu- Amd 9590, 16gbs of G Skill Ram, Gpu- GTX 760 windforce 3 edition 2gb. A Thermaltake water 2.0 water cooler for my cpu. Keyboard- Thermaltake Posieden , Case- 750D, Mobo Asus 990fx R2.0. 24 inch Dell LED monitor

Link to comment
Share on other sites

Link to post
Share on other sites

 

Wait never mind I just added the code

<?php
header('Content-disposition: attachment; filename=movie.mp4');
header('Content-type: video/mp4');
readfile('movie.mp4');
?>
to a php file and now it works.

 

if that code works, then the file is in the same directory as the webpage, so the url you typed for the link was wrong

this will work

 <li><a href="movie.mp4">Download</a></li> 

I have another question. How do I code the path to a file thats on another drive. Like say my website is on drive E and when I click on a link I want it to pull a file from drive Y. How would I do this? Would the path be "Y:NetworkStorage/movie.mp4" ?

if you open that folder in windows explorer, you will see that the path is

Y:/NetworkStorage/movie.mp4

i don't know if that will work though, i'm not sure which kind of permissions are given to php, just give it a try

Link to comment
Share on other sites

Link to post
Share on other sites

if that code works, then the file is in the same directory as the webpage, so the url you typed for the link was wrong

this will work

 <li><a href="movie.mp4">Download</a></li> 

No I have the file in a sub folder and I've already tried that. Apparently it has to be told which files it can let the browser download(idk).

 

Y:/NetworkStorage/movie.mp4

i don't know if that will work though, i'm not sure which kind of permissions are given to php, just give it a try

It doesn't work :/ 

Gaming rig- Cpu- Amd 9590, 16gbs of G Skill Ram, Gpu- GTX 760 windforce 3 edition 2gb. A Thermaltake water 2.0 water cooler for my cpu. Keyboard- Thermaltake Posieden , Case- 750D, Mobo Asus 990fx R2.0. 24 inch Dell LED monitor

Link to comment
Share on other sites

Link to post
Share on other sites

Make sure that your webserver (Apache or Nginx or whatever) is set up to deliver the appropriate Content types. If it isn't configured correctly, it can't deliver certain files. Most webservers need to know what sorts of files you want to be able to deliver.

EDIT: I see you seem to have solved that issue. Should have read the full thread first.

For Network storage, how are you using the path that Ciccioo gave you?

EDIT 2: here is a script I used to solve the download problem a while back, feel free to use it:

<?php$file = '';for ($i = 3; $i < count($_SESSION['pages']); $i++) {	$file .= $_SESSION['pages'][$i];	if ($i < count($_SESSION['pages'])-1)		$file .= '/';}download_file($file);function download_file( $fullPath ){  // Must be fresh start  if( headers_sent() )    die('Headers Sent');  // Required for some browsers  if(ini_get('zlib.output_compression'))    ini_set('zlib.output_compression', 'Off');  // File Exists?  if( file_exists($fullPath) ){    // Parse Info / Get Extension    $fsize = filesize($fullPath);    $path_parts = pathinfo($fullPath);    $ext = strtolower($path_parts["extension"]);    // Determine Content Type    switch ($ext) {      case "pdf": $ctype="application/pdf"; break;      case "exe": $ctype="application/octet-stream"; break;      case "zip": $ctype="application/zip"; break;      case "doc": $ctype="application/msword"; break;      case "xls": $ctype="application/vnd.ms-excel"; break;      case "ppt": $ctype="application/vnd.ms-powerpoint"; break;      case "gif": $ctype="image/gif"; break;      case "png": $ctype="image/png"; break;      case "jpeg":      case "jpg": $ctype="image/jpg"; break;      default: $ctype="application/force-download";    }    header("Pragma: public"); // required    header("Expires: 0");    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");    header("Cache-Control: private",false); // required for certain browsers    header("Content-Type: $ctype");    header("Content-Disposition: attachment; filename=\"".basename($fullPath)."\";" );    header("Content-Transfer-Encoding: binary");    header("Content-Length: ".$fsize);    ob_clean();    flush();    readfile( $fullPath );  } else    die('File Not Found');}?>

You may have to edit the code which retreives the file name/path as I encoded it in a pretty URL... you might like to use $_GET instead.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×