0

クロムからファイルをダウンロードできるアプリケーションを作成したいのですが、別の場所やビジュアルベーシックのWebブラウザコントロールではなく、クロムでファイルをダウンロードするだけでよいので、以下のコードを使用してファイルをダウンロードします。

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Process.Start("chrome.exe", "http://zbigz.com/file/1c3d3743dcb8f1d438d71fdc3137e0b79aaa4209/2")
End Sub

そしてダウンロードになります。しかし、私の主な問題は、ダウンロードする前にダウンロードしたファイル名を変更できないことです。ファイルをダウンロードするためのChrome設定で「ダウンロードする前に各ファイルを保存する場所を確認する」をオンにすると、ファイル名と場所を取得するためにsavefiledialogがポップアップします。これらのフィールドを埋める方法を知る必要があります。

誰かがクロムのダウンロードファイル名を変更する別の方法を持っている場合は、私に知らせてください. ありがとう

4

2 に答える 2

0

したがって、PHP でこれを行う場合は、次のコードを使用します。

<?php
//Filepath is the full url to your file
$filepath="http://www.example.com/examplefile";
//Filename is the name you want to display for the file, even if the files name is "1" you can set the name to be "2"
$filename='Example Name Here';
//The files description:
$filedescription='This is my example file';


//The first line here contains the filetype of the file, so that it can be open correctly.
//This example is .pdf, but you can use other filetypes - as told later on

//This following "block" contains information about the file
header('Content-Type: application/pdf');
    header("Content-Transfer-Encoding: Binary"); 
    header("Content-disposition: attachment; filename=" . $filename); 
    header("Content-Description: $filedescription");             
    header("Content-Length: " . filesize($filepath));

//Download the file
    readfile($filepath);
?>

ファイルが .pdf でない場合は、さまざまなファイル タイプの完全なリストについては、 http ://webdesign.about.com/od/multimedia/a/mime-types-by-content-type.htm を参照してください。

したがって、ファイルが .jpg の場合、コードは次のようになります。

header('Content-Type: image/jpeg');

それ以外の;

header('Content-Type: application/pdf');

つまり... このスクリプトが行うことは、ブラウザから開くと、ダウンロードしようとしているファイルを取得し、ダウンロードする前に情報を変更することです。ファイルはウェブサーバーまたは(これについては不明ですが)Dropbox アカウントにアップロードできます。

VB コードは次のようになります。

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
//The url should be the one to your .php file
    Process.Start("chrome.exe", "http://example.com/example.php")
End Sub

PHPなどに慣れていない場合、これは非常にぼやけている可能性がありますが、恐れることはありません-私がお手伝いします! 何か問題があればコメントしてください;)

于 2013-04-04T11:08:42.900 に答える