symfony1 - How to download a file on clicking thefile path using PHP-Symfony? -


i'm creating website using symfony blogging. users can upload posts site. when user add file save inside web/upload/file_upload , file path save in add_post table. when admin view add_post table template can see path of downloaded file of each , every user, want through file path download file.

how can this?

edit 1:

model - blog_user module - post

table structre - table name- blog_user

 1  user_id      bigint(20)        2 gender       varchar(255)               3  blog_status  tinyint(1)        4 file         varchar(255)  

form

'user_id' => new sfwidgetforminputhidden(),  'gender'  => new sfwidgetforminputtext(),  'file'    => new sfwidgetforminputfile(),  

here when uploading file, filepath save in blog_user table , file save inside web/upload directory.

edit 2:

//save file method

public function savefile(){     $file = $this->getvalue('file');     if(isset($file)){         $filename = 'post_uploaded -' .($file->getoriginalname());         $file->save(sfconfig::get('sf_upload_dir').'/post_upload'.'/'.$filename);     } } 

e:\xampp\htdocs\trunk\web\uploads\post_upload\post_uploaded -js.pdf

this how saved in side web/upload/post_upload directory , same path save inside db also

edit 3:

when user upload blog save in blog_user table , consist blog _id primary key, user_id on user table. want when user upload file , both user_id , , blog_id should saved inside blog table . how it?

user table - user_id , file(uploaded file)

blog table - blog_id - there blog titles , each title has unique blog id , user can upload file under each titles,

post table - post_id, blog_id, user_id

assuming:

  • your module name modulename
  • the model file bloguser
  • the primary key of model id

i go way:

in template:

<a href="<?php echo url_for('post/download?user_id='.$blog_user->getuserid()) ?>">download file</a> 

then, in action (use function miqdad ali):

  public function executedownload(sfwebrequest $request)   {     $blog_user = doctrine_core::gettable('blog_user')->find($request->getparameter('user_id'));     $this->forward404unless($blog_user);      header('content-type:');     header('content-description: file transfer');     //header('content-type: application/octet-stream');     header('content-disposition: attachment; filename='.basename($blog_user->getfile()));     header('content-transfer-encoding: binary');     header('expires: 0');     header('cache-control: must-revalidate, post-check=0, pre-check=0');     header('pragma: public');     header('content-length: ' . filesize($blog_user->getfile()));     ob_clean();     flush();      readfile($blog_user->getfile());      return sfview::none;   } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -