is it possible to upload files to web page and then access file data on website using $_FILES['file'] in php?
Use the following code to send file name to php file as POST value and it also stores the returned value
WebClient client = new WebClient();
byte[] bret = client.UploadFile(webpath, "POST", filepath);
string sret = System.Text.Encoding.ASCII.GetString(bret);
You have to modify your webserver in some way to answer POST requests with the appropriate actions. If you can't acces your server, you can't upload to it with C#; there is no 'standard' way to do this.
Related
I need to be able to download a file from url. The url does not link to an actual file instead it generates the file on the server first and then gives a download dialog. Probably returning an mvc FileResult.
I'm just interested in getting the byte[] from the file.
I've tried:
using (var webClient = new WebClient())
{
System.Uri uri = new System.Uri(Document.Url);
bytes = await webClient.DownloadDataTaskAsync(uri);
}
This works but I get a corrupted file as expected.
I do not have control over how the server generates or serves the file.
Any way to wait for the file to complete generating and then get the file content?
TIA
Never mind. Turns out the link returns some javascript that auto authenticates a user and then does a jquery get to another url and port to generate the file. So I was basically downloading that script and saving it to pdf. doh.
So a work around would be to mimic that in some way.
i have two domains like domain1 and domain2.
I'm uploading file to domain1's server with server.SaveAs method which uploads file to domain1
i want to upload same file to domain2 as well as domain1. can you people suggest me how can i do that.
how can i pass docx file into querystring ?
please do not ask me to use ftp.
You can upload file to other domain from the server side using the WebClient.UploadFile When the file is uploaded to the domain of current page and is saved. You can upload it to other domain using the URL.
string fileName = "PhysicalPath";
WebClient myWebClient = new WebClient();
byte[] responseArray = myWebClient.UploadFile(uriString,fileName);
Issue resolved when we created an asp.net web api and deployed it to 2nd domain.
Im looking for solution how can I upload some file using http request. I got the idea that I'll transfer my files by post and on PHP side I'll put files on the server.
How doin this?
var client = new System.Net.WebClient();
client.UploadFile(address, filename);
See UploadFile on MSDN.
Well I'd try the simplest possible thing that might work to start with - WebClient.UploadFile:
WebClient client = new WebClient();
client.UploadFile(url, file);
Of course, you'll have to write appropriate PHP code to handle the upload...
One more approach is to upload file via browser and handle upload request/response with Fiddler. After that, you can write exact request using HttpWebRequest via C#.
I am currently working on a fileUploader in the C# language for a image hosting site I develop for, I am currently wondering what the best approach is to uploading files to the server(all php/sql) with the client software being C#.
Also, how would I process these uploads in a PHP script, would you say something along the lines of:
upload.php?appfile=filepath?
Thanks,
You can use the WebClient Class and its UploadFile Method:
using (var wc = new WebClient())
{
wc.UploadFile("http://www.example.com/upload.php", "somefile.dat");
}
The UploadFile Method uses the POST method to upload the file to the HTTP resource; you need to set up your PHP script accordingly.
C# provides functionality to submit a post request, but there is nothing about uploading an image/file on MSDN. I'd like to do this without using raw headers.
Related questions
Upload files with HTTPWebrequest (multipart/form-data)
You can use WebClient class easily. It has an UploadFile method:
var client = new WebClient();
client.UploadFile("http://server/upload.aspx", #"C:\file.jpg");
My ASP.NET Upload FAQ has an article on this, with example code: Upload files using an RFC 1867 POST request with HttpWebRequest/WebClient. This code doesn't load files into memory, supports multiple files, and supports form values, setting credentials and cookies, etc.