Tyrocx Posted November 5, 2009 Share Posted November 5, 2009 Hi, I am developing in a vb.net silverlight app and posting a file stream to my php script so that I can upload a file within the silverlight app. Everything works except no data gets sent. I am new to file streaming through php so not sure what is going wrong. the result after the upload button is pressed, on the ftp server the file appears in the same directory as the php script but with 0 bytes. I am using bluehost (linux servers) but the silverlight app is on my desktop and posting to a url, not localhost (shared directory with webpage).. which i'm thinking could be the problem. Below is the code to both the silverlight and the php. Please let me know if any of you know whats going on Here is my Silverlight Code Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Dim dlg As New OpenFileDialog() dlg.Multiselect = False dlg.Filter = "All Files | *.*" If dlg.ShowDialog() Then UploadFile(dlg.File.ToString, dlg.File.OpenRead) End If End Sub Private s As Stream Private Sub UploadFile(ByVal fileName As String, ByVal data As Stream) Dim ub As New UriBuilder("http://www.mydomain.com/upload.php") ub.Query = String.Format("filename={0}", fileName) Dim c As New WebClient() s = data AddHandler c.OpenWriteCompleted, AddressOf c_OpenWriteCompleted c.OpenWriteAsync(ub.Uri, "Post") End Sub Private Sub c_OpenWriteCompleted(ByVal sender As Object, ByVal e As OpenWriteCompletedEventArgs) PushData(s, e.Result) e.Result.Close() s.Close() End Sub Private Sub PushData(ByVal Input As Stream, ByVal Output As Stream) Dim buffer(4096) As Byte Dim bytesread As Integer While ((bytesread = Input.Read(buffer, 0, buffer.Length)) <> 0) Output.Write(buffer, 0, bytesread) End While End Sub Here is my PHP code. $filepath = $_REQUEST['filename']; $handle = fopen("php://input", "r"); $file = fopen($filepath,"w"); if($file != null && $handle != null) { while ($data = fread($handle, 8192)) fwrite($file, $data); fclose($handle); fclose($file); } Quote Link to comment https://forums.phpfreaks.com/topic/180468-solved-file-upload-is-not-fully-working/ Share on other sites More sharing options...
Tyrocx Posted November 5, 2009 Author Share Posted November 5, 2009 problem with stream code in vb, I found the problem. Private Sub PushData(ByVal Output As Stream) Dim size As Integer = 4096 Dim buffer(4096) As Byte Dim bytesread As Integer = s.Read(buffer, 0, size) While (bytesread > 0) Output.Write(buffer, 0, bytesread) bytesread = s.Read(buffer, 0, size) End While End Sub Quote Link to comment https://forums.phpfreaks.com/topic/180468-solved-file-upload-is-not-fully-working/#findComment-952095 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.