2017-03-03 6 views
1

PHPを使用しているときに出力ドキュメントをサーバー上のフォルダに保存しようとしています。コードはそれを自分のコンピュータに保存しますが、ファイルを名前のフォルダ内に保存する必要があります。出力ドキュメントをPHPで保存する

コードを確認してください:

// Save File 
$h2d_file_uri = tempnam('', 'htd'); 
$objWriter = PHPWord_IOFactory::createWriter($phpword_object, 'Word2007'); 
$objWriter->save($h2d_file_uri); 

// Download the file: 
header('Content-Description: File Transfer'); 
header('Content-Type: application/octet-stream'); 
header('Content-Disposition: attachment; filename=example.docx'); 
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($h2d_file_uri)); 
ob_clean(); 
flush(); 
$status = readfile($h2d_file_uri); 
unlink($h2d_file_uri); 
exit; 

私はますfile_put_contents( 'test.txtの'、のfile_get_contents( 'http://web.comを'))試してみました。それは私を助けなかった。ファイルをフォルダに保存する方法を教えてください。

答えて

0

名前を持つフォルダに出力を保存するには、このコードを使用して、フォルダ名とファイル名を指定してください。 $ fileName = $ _SERVER ['DOCUMENT_ROOT'] '/ download/muraripradip.docx'; $ objWriter = PHPWord_IOFactory :: createWriter($ phpword_object、 'Word2007');

0

あなたが必要としないものをたくさんしているようです。ファイルをダウンロードする場合を除き、あなたからすべてのコードをスキップすることができます。

は、このコードをONにする::

// Save File 
$h2d_file_uri = tempnam('', 'htd'); 
$objWriter = PHPWord_IOFactory::createWriter($phpword_object, 'Word2007'); 
$objWriter->save($h2d_file_uri); 

// Download the file: - And below that point 

あなただけの既存のコードを少し変更することができように見えますこの中へ

// Save File 
$h2d_file_uri = $_SERVER['DOCUMENT_ROOT'].'/docs/some_file_name.docx'; 
$objWriter = PHPWord_IOFactory::createWriter($phpword_object, 'Word2007'); 
$objWriter->save($h2d_file_uri); 

その後、http://domian.tld/docs/some_file_name.docxフォルダに保存されます。あなたは公共がアクセスすることが許可されていないどこかでそれを保存することができます。

関連する問題