vb.net-在chrome中设置下载文件的名称
我想制作一个可以从chrome下载文件的应用程序,我只需要在chrome中下载文件,而不是在visual basic中的其他位置或webbrowser控件,因此我使用以下代码下载文件:vb.net-在chrome中设置下载文件的名称,vb.net,google-chrome,Vb.net,Google Chrome,我想制作一个可以从chrome下载文件的应用程序,我只需要在chrome中下载文件,而不是在visual basic中的其他位置或webbrowser控件,因此我使用以下代码下载文件: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Process.Start("chrome.exe", "http://zbigz.com
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来获取文件名和位置。我需要知道如何填补这些空白
如果有人有其他方法更改chrome的下载文件名,请注意我。
谢谢因此,如果您想在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);
?>
而不是
header('Content-Type: application/pdf');
所以。。。
这个脚本将做的是,当它从浏览器打开时,它会获取您试图下载的文件,并在下载之前更改信息。
该文件可以上载到Web服务器或(对此不确定)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之类的东西,这可能会很模糊,但恐怕不行——我会帮你的!
如果有什么不对劲,就发表评论;) 真是太古怪了!
尝试重写页面以包含内容。
目前,页面只包含脚本
<?php
$filepath="http://www.internetdownloadmanager.com/pictures/IDM_title.gif";
$filename='IDM_title.gif';
header('Content-Type: image/gif');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=" . $filename);
header("Content-Length: " . filesize($filepath));
readfile($filepath);
?>
<!--A simple html-->
<html>
<header>
<title>Downloading</title>
</header>
<body>
<label>Redirecting to download</label>
</body>
</html>
正在下载
重定向到下载
将文件重命名为“index.html”,并将其放入“muviz.net/download/”文件夹中,然后您将能够转到“”地址并下载您的文件!希望如此;) 最简单的方法是重命名文件,如果不可能的话,另一个选择(从vb.net之外)是下载文件的PHP脚本-将Google Chrome链接到PHP脚本和voíla!如果你需要持续的帮助,请告诉我。谢谢你的回复。它真的帮助了我。如果你能给一个php脚本的例子,这将是伟大的。再次感谢…再次感谢您的回复。我用我的脚本为你发布我的问题。
<?php
$filepath="http://www.internetdownloadmanager.com/pictures/IDM_title.gif";
$filename='IDM_title.gif';
header('Content-Type: image/gif');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=" . $filename);
header("Content-Length: " . filesize($filepath));
readfile($filepath);
?>
<!--A simple html-->
<html>
<header>
<title>Downloading</title>
</header>
<body>
<label>Redirecting to download</label>
</body>
</html>