Click here to Skip to main content
15,879,326 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
Questionuploading file via post Pin
0b4m418-Jan-11 23:13
0b4m418-Jan-11 23:13 
AnswerRe: uploading file via post Pin
Niall Barr19-Jan-11 2:32
professionalNiall Barr19-Jan-11 2:32 
GeneralRe: uploading file via post Pin
0b4m419-Jan-11 3:27
0b4m419-Jan-11 3:27 
GeneralRe: uploading file via post Pin
Niall Barr19-Jan-11 5:10
professionalNiall Barr19-Jan-11 5:10 
GeneralRe: uploading file via post Pin
0b4m419-Jan-11 5:49
0b4m419-Jan-11 5:49 
GeneralRe: uploading file via post Pin
Niall Barr19-Jan-11 6:04
professionalNiall Barr19-Jan-11 6:04 
GeneralRe: uploading file via post Pin
0b4m419-Jan-11 6:11
0b4m419-Jan-11 6:11 
GeneralRe: uploading file via post Pin
Niall Barr22-Jan-11 1:31
professionalNiall Barr22-Jan-11 1:31 
It occured to me that it's likely that the site you're posting to expects an attached file rather than the file content in a post field called file...

If that's the case, then this code should work.

<?php
function datapost($URLServer,$postdata)
{
	$agent = "Mozilla/5.0";
	$cURL_Session = curl_init();
	curl_setopt($cURL_Session, CURLOPT_URL,$URLServer);
	curl_setopt($cURL_Session, CURLOPT_USERAGENT, $agent);
	curl_setopt($cURL_Session, CURLOPT_POST, 1);
    curl_setopt($cURL_Session, CURLOPT_POSTFIELDS,$postdata);
	$result = curl_exec($cURL_Session);
	curl_setopt($cURL_Session, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($cURL_Session, CURLOPT_FOLLOWLOCATION, 1);

	return $result;
}


$postdata = array();
$postdata['Id'] = '12340';
$postdata['profileName'] = 'tsunami';

// Create a local file to be attached (only needed if the file is not local)
$tmpfile = tempnam(false,'tmp_');
$filedata = file_get_contents("http://localhost/tmp/test.csv");
file_put_contents($tmpfile, $filedata);
// Putting an @ before the filename gats cURL to attach a file
$postdata['file'] = "@$tmpfile";

$postdata['submit'] = urlencode('submit');
$source= datapost("http://localhost/tmp/posthere.php",$postdata);
// Clean up
unlink($tmpfile);

echo $source;

?>

GeneralRe: uploading file via post Pin
0b4m425-Jan-11 4:11
0b4m425-Jan-11 4:11 
QuestionWhich PHP framework to use? [modified] Pin
skqi15-Jan-11 20:08
skqi15-Jan-11 20:08 
AnswerRe: Which PHP framework to use? Pin
chiryphp16-Jan-11 13:49
chiryphp16-Jan-11 13:49 
GeneralRe: Which PHP framework to use? Pin
skqi29-Jan-11 1:22
skqi29-Jan-11 1:22 
QuestionComments postings on websites - need help pls... Pin
bdesi14-Jan-11 7:23
bdesi14-Jan-11 7:23 
AnswerRe: Comments postings on websites - need help pls... Pin
shamly15-Jan-11 6:01
shamly15-Jan-11 6:01 
GeneralRe: Comments postings on websites - need help pls... Pin
cjoki17-Jan-11 4:55
cjoki17-Jan-11 4:55 
GeneralRe: Comments postings on websites - need help pls... Pin
shamly17-Jan-11 5:14
shamly17-Jan-11 5:14 
AnswerRe: Comments postings on websites - need help pls... Pin
effayqueue19-Mar-11 2:48
effayqueue19-Mar-11 2:48 
QuestionHelp running php scripts locally and/or conversion to executable format Pin
ldsdbomber14-Jan-11 1:34
ldsdbomber14-Jan-11 1:34 
AnswerRe: Help running php scripts locally and/or conversion to executable format Pin
cjoki14-Jan-11 4:40
cjoki14-Jan-11 4:40 
QuestionSear Engines (Google search / Yahoo Search ) Pin
bdesi13-Jan-11 21:54
bdesi13-Jan-11 21:54 
AnswerRe: Sear Engines (Google search / Yahoo Search ) Pin
Gerben Jongerius14-Jan-11 2:51
Gerben Jongerius14-Jan-11 2:51 
AnswerRe: Sear Engines (Google search / Yahoo Search ) Pin
skqi9-Feb-11 0:25
skqi9-Feb-11 0:25 
Questionsockets and servers for game hosting Pin
shahab9612-Jan-11 17:14
shahab9612-Jan-11 17:14 
QuestionRe: sockets and servers for game hosting Pin
Murlakatamus21-Jan-11 21:30
Murlakatamus21-Jan-11 21:30 
AnswerRe: sockets and servers for game hosting Pin
shahab9621-Jan-11 22:15
shahab9621-Jan-11 22:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.