473,461 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Upload a file to a webserver using C# and PHP

I was looking for a simple way to upload a file to a webserver from a
standalone C# windows application, I had a lot of trouble finding a
simple solution but ran a simple way(note: I have not checked to see
what the filesize limitations and stuff are but works great so far,
most likely the size limit is specified in the php.ini, but can be
overridden in your script)

Anyway this just simply passes the file to a php script on a webserver
and moves it to the folder specified in your php script, or you could
pass a directory as a variable I guess :-)

================================================== =========
C# Upload file to PHP Script

================================================== =========
C# Part ------
using System.Net;
....

//THIS UPLOADS THE FILE THROUGH A PHP SCRIPT ON THE SERVER.
WebClient client = new WebClient();
client.UploadFile("https://www.mywebsite.com/uploadtome.php","c:\\File.txt");
================================================== =========
PHP Part ------

<?php
$ftmp = $_FILES['file']['tmp_name'];
$oname = $_FILES['file']['name'];
$fname = '/Textfiles/' . $oname;
if(move_uploaded_file($ftmp, $fname)){
echo "Done";
exit();
} else {
echo "Failed";
}
?>

================================================== =========

Tim Geiges
ti********@gmail.com
PHP Programmer
LoanToolbox.com

Jun 30 '06 #1
0 1287

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Philippe Lemmerling | last post by:
I have a question concerning security of my file upload script. I'm using the php upload routines (move_uploaded_file,...) and variables ($_FILES) to upload images to a webdirectory. Everything...
15
by: Simon | last post by:
I would like to create a very basic file upload add image form to add to my web site and to keep them in a "tmp" directory within my web hosting file manager once uploaded. I understand the basic...
3
by: fred4534 | last post by:
Hello, I'm using the GoAhead embedded Webserver (http://webserver.goahead.com/webserver/webserver.htm) which can use only ASP and a set of javascript instructions. I'm trying to make an upload...
1
by: Chris Fink | last post by:
I am using the html input type=file to upload files to the webserver. This is working fine, but only for files less than ~3mb in size. When I attempt to upload a file >3mb, i immediatley receive a...
2
by: Tom Wells | last post by:
I have a little file upload page that I have been able to use to successfully upload files to the C: drive of LocalHost (my machine). I need to be able to upload to a network drive from the intranet...
3
by: Mike Kelly | last post by:
Hi. I've built a page using standard ASP.NET 2.0 features and when I upload a large file (>20MB) to our intranet server, I get a paltry 100KB/s on our 100Mb/s LAN. Simply copying the file, I get...
4
by: Tony B | last post by:
I've moved an existing site (which I didn't write) from a apache/php/mysql host under windows to a linux apache/php/mysql host. I've sorted out most problems except one. There is an upload...
7
by: MDB | last post by:
Anyone have any pointers / links / examples on how to upload files through FTP? I am currently using the built in file upload control however it seems to take a very long time to upload files and...
16
by: Lawrence Krubner | last post by:
To guard against our users possibly uploading huge files, I've got this in my php.ini file: ; Maximum size of POST data that PHP will accept. post_max_size = 10M On a server running Ubuntu...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.