So I made a script to upload a file :
<html>
<body>
<form enctype="multipart/form-data" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
Choose a file to upload: <input name="uploaded_file" type="file" />
<input type="submit" value="Upload" />
</form>
<?php
include 'global.php';
//Check that we have a file
if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0))
{
//Check if the file size is less than 350Kb
$filename = basename($_FILES['uploaded_file']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($_FILES["uploaded_file"]["size"] < 20971520))
{
//Determine the path to which we want to save this file
$newfilename = rand(1, 224323443738507);
$newname = dirname(__FILE__).'/upload/'.$newfilename;
//Attempt to move the uploaded file to it's new place
if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname)))
{
$rand = rand(1, 1024) . "_" . rand(3, 2673) . "_" . rand(5, 7337);
$name = $_FILES["uploaded_file"]["name"];
mysql_query("INSERT INTO uploads(id, name, todownloadname, path) VALUES('" . $rand . "', '" . $newfilename . "', '" . $name . "', '" . $newname . "')")or die(mysql_error());
echo "It's done! The file has been saved <a href=download.php?id=" . $rand . "> ->>here<<- " . "</a>";
}
else
{
echo "Error: A problem occurred during file upload!";
}
}
else
{
echo "Error: Only files under 20mb are accepted for upload";
}
}
else
{
echo "Error: No file uploaded";
}
?>
</body>
</html>
and I coded a function to upload the file in vb.net but it's not working for some reason. code:
If Not TextBox1.Text = "" Then
Dim filepath, feedbackUrl As String
filepath = TextBox1.Text
feedbackUrl = "http://www.googler.co.cc/"
Dim MyFile As New FileInfo(filepath)
If MyFile.Length < 20971520 Then
Dim boundery As String = IO.Path.GetRandomFileName
Dim header As New System.Text.StringBuilder()
header.AppendLine("--" & boundery)
header.Append("Content-Disposition: form-data; name=""userfile"";")
header.AppendFormat("filename=""{0}""", IO.Path.GetFileName(filepath))
header.AppendLine()
header.AppendLine("Content-Type: application/octet-stream")
header.AppendLine()
'Convert in binary format (ASCII)
Dim headerbytes() As Byte = System.Text.Encoding.UTF8.GetBytes(header.ToString)
Dim endboundarybytes() As Byte = System.Text.Encoding.ASCII.GetBytes(vbNewLine & "--" & boundery & "--" & vbNewLine)
'Create and initialize the request
Dim request As HttpWebRequest = DirectCast(WebRequest.Create(feedbackUrl), HttpWebRequest)
request.UserAgent = "Mozilla/5.0 () AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7"
request.Method = "POST"
'Write POST data to request
request.ContentType = "multipart/form-data; boundary=" & boundery
request.ContentLength = headerbytes.Length + New FileInfo(filepath).Length + endboundarybytes.Length
Dim filebytes() As Byte = My.Computer.FileSystem.ReadAllBytes(filepath)
Dim requestStream As System.IO.Stream = request.GetRequestStream()
requestStream.Write(headerbytes, 0, headerbytes.Length)
requestStream.Write(filebytes, 0, filebytes.Length)
requestStream.Write(endboundarybytes, 0, endboundarybytes.Length)
requestStream.Close()
'Execute request and read response.
Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
Dim streamgt As System.IO.Stream = response.GetResponseStream()
Dim length As Int64 = 100000
Dim txt(length) As Byte
streamgt.Read(txt, 0, length)
streamgt.Close()
streamgt.Dispose()
TextBox2.Text = System.Convert.ToString(txt)
Else
MsgBox("File is bigger than 20MB")
End If
Else
MsgBox("Enter path to file")
End If
Any help is appreciated!