0

ok what i have users do is upload files to the server, the files gets renamed for conflicting issues, and then they choose a name they want to call the file. After it uploads it sends that info to the database.

now i know that they are going to want to download that file but i don't know how to do a force download. Not only that but i would like to change the file name that they are going to download (not on the server) to there user friendly name.

i have searched the web but i find things that are more complicated than i think i needs to be or i don't understand it.

so i am asking all of you genius's for a way to do this. I think the idea of it would have to be on another file that executes it all

4
Contributors
7
Replies
9
Views
8 Years
Discussion Span
Last Post by itisnot_me
0

You can use my desktop_write module. As you will see, the actual code to do it is pretty simple. This just packages it for you and provides the option of different output file types.

desktop_write

0

You want to use the following in a new file (download.php)

// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');

change the filename parameter to what they called the file in the db and use the correct extension. Also change the content type header

0

You want to use the following in a new file (download.php)

// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');

change the filename parameter to what they called the file in the db and use the correct extension. Also change the content type header

thanks that works on what i needed. of course with a little bit more coding to do some things

$ext = substr(strrchr($file, "."), 1);

  if ($ext == pdf){
	  $ctype="application/pdf";
  }
  if ($ext == doc){
	  $ctype="application/msword";
  }
  if ($ext == xls){
	  $ctype="application/vnd.ms-excel";
  }
  if ($ext == ppt){
	  $ctype="application/vnd.ms-powerpoint";
  }
  
// We'll be outputting a PDF
header('Content-type: '.$ctype.'');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="'.$name.'.'.$ext.'"');


	}
?>

Now i have the problem that it is not downloading correctly. i transfered the file off my server and they work perfectly. but when i run this script it downloads as a corrupt or empty file

any thoughts?

0

try adding readfile at the end

.....
header('Content-Disposition: attachment; filename="'.$name.'.'.$ext.'"');
readfile($file);
?>
0

also just to optimize the php code you have, I would switch to a switch statement instead of going through a ton of if statements.

Also, the code you entered didn't parse correctly, did it? I don't see any single quotes around the constant literals
if ($ext == 'pdf'){

0

thanks for the tip.

now i think i know what the problem is. it is not finding the document cause it is in the folder. now i did try to put it in the filename but it just outputs the directory with the name.

i was looking through some of the complex examples that saw but did not see there they are getting the directory.

i am stumped

0

bump...

would anyone know how to specify the directory that the files would be in?

i tried to just put it in the directory but it gave me a server error

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.