Click here to Skip to main content
12,454,104 members (56,489 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++ IIS PHP
Hi all!

How I can upload file to an HTTP Server (php script) with POST Method?

I need to upload some small text files simultaneously in C++. What will be the PHP script?

Please, help!
Posted 28-Dec-12 0:37am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

If the HTML form was something like this:
<form enctype="multipart/form-data" action="script.php" method="POST">
  <input name="uploaded_file[]" type="file" />
  <input name="uploaded_file[]" type="file" />
  <input name="uploaded_file[]" type="file" />
  <input type="submit" value="Upload" />
 </form>

Then the PHP script will be:
if(isset($_FILES['uploaded_file'])){ // check if any file was uploaded
for ($i = 0; $i < count ($_FILES['uploaded_file']); $i++) { // loop through files

if (move_uploaded_file ($_FILES['uploaded_file']['tmp_name'][$i], "target_directory/".$_FILES['uploaded_file']['name'][$i])) {
// upload succeeded 
}
 
}
 

}

Also make shure that php.ini upload_max_filesize and max_post_size values are set at appropiate values.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100