Question Someone who knows both PHP and VB.NET, I need your help.

n00bl3z

New member
Joined
Nov 13, 2009
Messages
1
Programming Experience
1-3
Alrite, I'm making an API for my website that i'll be able to utilize over VB.NET;

So far the only thing i'm having problems with is uploading files;

I'm trying to keep it as simple as possible on the .net side, so my PHP Script needs all the variables to be in the function;

I know how to post a file via HTTP, But when I use this vb.net code:
VB.NET:
Function upFile(ByVal uploadUrl As String, ByVal filePath As String) As String
        Dim fileToUpload = filePath
        Dim rdr As New FileStream(fileToUpload, FileMode.Open)
        Dim req As HttpWebRequest = DirectCast(WebRequest.Create(uploadUrl), HttpWebRequest)
        req.Method = "PUT"
        req.ContentLength = rdr.Length
        req.AllowWriteStreamBuffering = True
        Dim reqStream As Stream = req.GetRequestStream()
        Dim inData As Byte() = New Byte(rdr.Length - 1) {}
        Dim bytesRead As Integer = rdr.Read(inData, 0, rdr.Length)
        reqStream.Write(inData, 0, rdr.Length)
        rdr.Close()
        req.GetResponse()
        reqStream.Close()
    End Function

with this php code:
PHP:
function uploadFile($target)
	{
		if (file_exists($target . @$_FILES["file"]["name"]))
      {
      die( $_FILES["file"]["name"] . " already exists. " );
      }
    else
      {
      move_uploaded_file(@$_FILES["file"]["tmp_name"],
      "upload/" . @$_FILES["file"]["name"]);
      die( "Upload Successful  --  Stored in: " . $target . @$_FILES["file"]["name"] );
      }
	}

the files don't upload... What am I doing wrong?
 
Back
Top