[英]VBSCRIPT Upload File to Server
I am trying to make a script to upload any file to a simple html/php upload form.我正在尝试制作一个脚本来将任何文件上传到一个简单的 html/php 上传表单。 I cannot find any working scripts that don't use ASP.
我找不到任何不使用 ASP 的工作脚本。 This is the closest code I have: (VBS)
这是我拥有的最接近的代码:(VBS)
Dim strURL
Dim HTTP
Dim dataFile
Dim dataRequest
Dim objStream
strURL = "http://10.0.0.50/~/v_upload/up.php"
Set HTTP = CreateObject("Microsoft.XMLHTTP")
Set objStream = CreateObject("ADODB.Stream")
Set dataFile = objStream.Read
objStream.Type = 2
objStream.Open
objStream.LoadFromFile "http.txt"
Set dataRequest = "dataFile=" & dataFile
HTTP.open "POST", strURL, False
HTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
HTTP.setRequestHeader "Content-Length", Len(dataRequest)
WScript.Echo "Now uploading file G:\Http\http.txt"
HTTP.send dataRequest
WScript.Echo HTTP.responseText
Set HTTP = Nothing
This give me this error:这给了我这个错误:
Line 9
9号线
Char 1字符 1
Error: Operation is not allowed when the object is closed错误:object关闭时不允许操作
Code 800A0E78代码 800A0E78
Source ADODB.Stream源 ADODB.Stream
The PHP code is: PHP 代码为:
<?php
if (!isset($_FILES['dataFile']['error']) || is_array($_FILES['dataFile']['error'])) {
switch ($_FILES['dataFile']['error']) {
case UPLOAD_ERR_OK:
break;
case UPLOAD_ERR_NO_FILE:
echo 'Unable to Upload. No file sent.';
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
echo 'Unable to Upload. Exceeded file size limit.';
default:
echo 'Unable to Upload. Unknown errors.';
}
die();
}
$file_path = "http/";
$file_path = $file_path . basename( $_FILES['dataFile']['name']);
if(move_uploaded_file($_FILES['dataFile']['tmp_name'], $file_path)) {
echo "File {$_FILE['dataFile']['name']} uploaded success";
} else{
echo "Unable to upload. Unable to move uploaded file.";
}
?>
Please Help!请帮忙!
There are basically 4 errors that need to be repaired:基本上有4个错误需要修复:
set
from line 9
line 9
删除set
objStream.Read
to objStream.ReadText
objStream.Read
到objStream.ReadText
line 9
to after objStream.LoadFromFile
line 9
移至objStream.LoadFromFile
之后set
from line 14
line 14
删除set
The Full Code:完整代码:
Dim strURL
Dim HTTP
Dim dataFile
Dim dataRequest
Dim objStream
strURL = "http://10.0.0.50/~/v_upload/up.php"
Set HTTP = CreateObject("Microsoft.XMLHTTP")
Set objStream = CreateObject("ADODB.Stream")
objStream.Type = 2
objStream.Open
objStream.LoadFromFile "http.txt"
dataFile = objStream.ReadText
dataRequest = "dataFile=" & dataFile
HTTP.open "POST", strURL, False
HTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
HTTP.setRequestHeader "Content-Length", Len(dataRequest)
WScript.Echo "Now uploading file G:\Http\http.txt"
HTTP.send dataRequest
WScript.Echo HTTP.responseText
Set HTTP = Nothing
This did not work for me, but I found this: https://github.com/ArancioGrigio/vbs-php-ImageUpload这对我不起作用,但我发现了这个: https : //github.com/ArancioGrigio/vbs-php-ImageUpload
It transfers image to a php server by converting them to base64 and sending the text to server in packets of 2000 character through php GET parameters.它通过将图像转换为 base64 并将文本以 2000 个字符的数据包通过 php GET 参数发送到服务器来将图像传输到 php 服务器。 At the end the php server converts text back to image.
最后,php 服务器将文本转换回图像。 I used vbs for client and php for server.
我使用 vbs 作为客户端和 php 作为服务器。 This is good for low traffic and low weight images, otherwise it could take some minutes and server could not respond anymore.
这对于低流量和低重量图像很有用,否则可能需要几分钟时间并且服务器无法再响应。 GET parameters limit is 2048 characters
GET 参数限制为 2048 个字符
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.