Current location: Hot Scripts Forums » Programming Languages » PHP » download and upload pdf and ms word (php and mysql)


download and upload pdf and ms word (php and mysql)

Reply
  #1 (permalink)  
Old 07-23-10, 02:24 PM
williamh26 williamh26 is offline
Wannabe Coder
 
Join Date: Jul 2010
Posts: 122
Thanks: 2
Thanked 0 Times in 0 Posts
download and upload pdf and ms word (php and mysql)

Now i have another question, How upload a pdf and ms word file into a database and then retrieve the files for upload????
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-24-10, 04:16 AM
nona1 nona1 is offline
New Member
 
Join Date: Jul 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Hi!

// I was able to upload files but I don't know to make them links for download

//To upload use this:

// make an html file with this form:

<form method="POST" action="upload.php" enctype="multipart/form-data">
<b>Upload your file here</b><br/>
<input name="userfile" type="file">&nbsp;
<br/>
<input type="submit" value="Upload" style="width: 150px">
</form>

//and the php file must look like this:

"upload.php"

$target="img/";
$target.=$_FILES['userfile']['name'];
move_uploaded_file($_FILES['userfile']['tmp_name'],$target);
mysql_query("INSERT INTO dbo.dbname(upload) VALUES ('".$target."')") or die( mysql_error());
echo "Upload done";

Into the DataBase make a table with a field text named upload for this exemple


For download I wait an answer pls!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-24-10, 05:10 AM
hala303 hala303 is offline
New Member
 
Join Date: Jul 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
you can download pdf file by using this code in two stage:
1- your first file download.php and it contain the following code:
<?php

// place this code inside a php file and call it f.e. "download.php"
$path = $_SERVER['DOCUMENT_ROOT']."/your_path/"; // change the path to fit your websites document structure
$fullPath = $path.$_GET['download_file'];

if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "pdf":
header("Content-type: application/pdf"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download
break;
case "doc":
header("Content-type: doc"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
exit;
?>
2- the scond stage make another file named it example and write on it the following code:

<a href="download.php?download_file=some_file.pdf">Do wnload here</a>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-24-10, 09:19 AM
williamh26 williamh26 is offline
Wannabe Coder
 
Join Date: Jul 2010
Posts: 122
Thanks: 2
Thanked 0 Times in 0 Posts
thank you i will try
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 09:07 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.