Uploading file from Synapse using HttpPostFile to PHP lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Nafees · 2016-03-08 10:19 I've been trying to upload binary files from synapse using HttpPostFile to a web server running on PHP. This is how I receive the file in PHP: Code: PHP  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i move_upload ed_file($_FILES["file"]["tmp_name"],'/uploads/'.$id.'.'.$fn); ^ $id and $fn are retrieved using $_GET. How do I use HttpPostFile to upload a binary file? ---------------------------------------------------------------------- Leledumbo · 2016-03-08 11:23 Err...just call it? What didn't you understand from the API docs? ---------------------------------------------------------------------- rvk · 2016-03-08 11:26 For uploading you can use HttpPostFile (you need a stream): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure UploadFile(FileName: string);var  Data: TFileStream;  URL: string;  rs: tStringlist;begin  if not FileExists(FileName) then Exit;  Data := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);  rs := tStringlist.Create;  try    URL := 'http://xxx.xxx.xxx/upload.php';  HttpPostFile_proxy(URL, 'uploadfile', FileName, Data, rs);  finally  Data.free;    rs.free;  end;end;(There is also HttpPostBinary() but that just sends a stream without option of filename) But you say $id and $fn are retrieved using $_GET. You do realize $_GET is only for GET and not for POST ?? You need to use $_FILES in PHP: http://php.net/manual/en/reserved.variables.files.php Quote$_FILES: An associative array of items uploaded to the current script via the HTTP POST method. So you can use the following variables: Code: PHP  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   print "path: ".$file_array['tmp_name']."
\n";  print "name: ".$file_array['name']."
\n";  print "type: ".$file_array['type']."
\n";  print "size: ".$file_array['size']."
\n"; ---------------------------------------------------------------------- Nafees · 2016-03-08 14:42 Quote from: rvk on March 08, 2016, 12:26:09 pmFor uploading you can use HttpPostFile (you need a stream): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure UploadFile(FileName: string);var  Data: TFileStream;  URL: string;  rs: tStringlist;begin  if not FileExists(FileName) then Exit;  Data := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);  rs := tStringlist.Create;  try    URL := 'http://xxx.xxx.xxx/upload.php';  HttpPostFile_proxy(URL, 'uploadfile', FileName, Data, rs);  finally  Data.free;    rs.free;  end;end;(There is also HttpPostBinary() but that just sends a stream without option of filename) But you say $id and $fn are retrieved using $_GET. You do realize $_GET is only for GET and not for POST ?? You need to use $_FILES in PHP: http://php.net/manual/en/reserved.variables.files.php Quote$_FILES: An associative array of items uploaded to the current script via the HTTP POST method. So you can use the following variables: Code: PHP  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   print "path: ".$file_array['tmp_name']."
\n";  print "name: ".$file_array['name']."
\n";  print "type: ".$file_array['type']."
\n";  print "size: ".$file_array['size']."
\n"; Your Pascal code gives me a "RunError(211)", in the file httpsend, Line 839: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ResultData.LoadFromStream(HTTP.Document); EDIT: I got that code to work, but the PHP code gives me these errors: QuoteWarning: move_uploaded_file(/uploads/1.q.txt): failed to open stream: No such file or directory in D:\wamp\www\qd125\qd125.php on line 37 and Warning: move_uploaded_file(): Unable to move 'C:\Windows\Temp\php5D42.tmp' to '/uploads/1.q.txt' in D:\wamp\www\qd125\qd125.php on line 37 ---------------------------------------------------------------------- rvk · 2016-03-08 14:52 Quote from: Nafees on March 08, 2016, 03:42:50 pmYour Pascal code gives me a "RunError(211)", in the file httpsend, Line 839: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ResultData.LoadFromStream(HTTP.Document);   Of course the HttpPostFile_proxy should have been HttpPostFile, but I guess you saw that too. For me this code works. rs (TStringList) is created so the ResultData should be written to rs. 211 is Call to abstract method and there is nothing abstract about TStringList. Please show your exact code. ---------------------------------------------------------------------- rvk · 2016-03-08 14:54 Quote from: Nafees on March 08, 2016, 03:42:50 pmEDIT: I got that code to work, but the PHP code gives me these errors: QuoteWarning: move_uploaded_file(/uploads/1.q.txt): failed to open stream: No such file or directory in D:\wamp\www\qd125\qd125.php on line 37 and Warning: move_uploaded_file(): Unable to move 'C:\Windows\Temp\php5D42.tmp' to '/uploads/1.q.txt' in D:\wamp\www\qd125\qd125.php on line 37 Then we need to see a lot more of the PHP-code. And what file are you uploading (name etc.). I have something like this: Code: PHP  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i

File Upload Results

$file_array) {   print "path: ".$file_array['tmp_name']."
\n";  print "name: ".$file_array['name']."
\n";  print "type: ".$file_array['type']."
\n";  print "size: ".$file_array['size']."
\n";  print "destination: ".$file_dir.$file_array['name']."
\n";   if (is_uploaded_file($file_array['tmp_name'])) {     $name=explode('.', $file_array['name']);     $file_array['name']=$name[0].'-'.date('Y-m-d.H.i.s').'.'.$name[1];   move_uploaded_file($file_array['tmp_name'], $file_dir.$file_array['name']) or die ("Couldn't copy");     print "file was moved!

";  }} ?> ---------------------------------------------------------------------- Nafees · 2016-03-08 15:11 It was just a small problem in the PHP code, I had a slash in the start of the second argument for move_uploaded_file!