[ESP8266] How to download from a PHP Page with HttpClient

Hey guys,

i’m working on an updateserver for all of my esp8266.

The server (php script) requests for the Firmware Type [ie. i have one build for the arduino 8relay from china] and askes for the versions number.
then the Script will check, if there is an update and will start an update.
But here is the problem:

Before i want to do the OTA Update with ESPhttpUpdate.update(…), i have to update a few datafiles, which are uploaded to the spiffs filesystem. [ie. setup.html, which contains the page on the picture]

Now i do a HTTP Request to the php file and this will send a new header with the files to upload:

function sendFile($path) {
	
    header($_SERVER["SERVER_PROTOCOL"].' 200 OK', true, 200);
    header('Content-Type: application/octet-stream', true);
    header('Content-Disposition: attachment; filename='.basename($path));
	header('Content-Length: '.filesize($path), true);
    header('x-MD5: '.md5_file($path), true);
    readfile($path);
	
}

(Testing on a Browser this works fine, i get a download with the file i need.)

On ESP i get the Filesize aswell, but i won’t get it to perform a download.

Could you please give me a hint, how to get a Filestream from the following http request?
Because all the Examples work only with a direct upload from a form. Not when i get a stream directly from my own request?

				if (update) {
					
					HTTPClient httpClient;
					log ("Link: " + configDaten.soft_link);
					httpClient.begin( configDaten.soft_link );  // Connection to the PHP Script
					httpClient.addHeader("Content-Type", "application/x-www-form-urlencoded");
					int httpCode = httpClient.POST("checkUpdate=true&name=" + _soft_name);
					
					
					String erg = httpClient.getString();   // Checks if update is avaible
					
					log ("Update Code: " + String(httpCode));
					log ("Ergebnis: " + erg);
					
					
					if( httpCode == 200 ) {
					  
					  
					  float newVersion = erg.toFloat();


						 log( "Current firmware version: " + _soft_version);
						 log( "Available firmware version: " + String(newVersion));
					  
					  
						if (newVersion > _soft_serial.toFloat() ) {     // If Update is avaible
							
							log ("Update wird geladen....");
							
							log ("Beginne mit SPIFFS Aktualisierung");
							log ("Lade Anzahl SPIFFS FILES");
							
							int httpCode = httpClient.POST("getNumberOfSpiffs=true&name=" + _soft_name + "&version=" + erg);
							String numberofspiffs = httpClient.getString();   // Request from the same Script the Number of Data, what has to be stored into the Spiffs (ig. setup.html, jquery librarie ...)
							
							if (numberofspiffs.substring(0,3) != "ERR") {
								
								int nfsp = numberofspiffs.toInt();
								log (String(nfsp) + " gefunden.");
								
								if (nfsp > 0) {     // it finds 4 Updates
									
									
									
									//for (int x=1; x < nfsp; x++) {
									for (int x=1; x < 2; x++) {
										log ("Beginne mit Download " + String (x) );
										
										int httpCode = httpClient.POST("getSPIFFSFiles=true&name=" + _soft_name + "&id=" + String(x) + "&version=" + erg);
										log ("HTTP Code für Download: " + String(httpCode));

										log ("Größe: " + String(httpClient.getSize())); // Here i get the correct Filesize.
										
// So what to do next? i think i just have something overlooked

// This does not work:
										/*HTTPUpload& upload = server.upload();
										
										if(upload.status == UPLOAD_FILE_START){
												String filename = upload.filename;
												if(!filename.startsWith("/")) filename = "/"+filename;
												fsUploadFile = SPIFFS.open(filename, "w");
												log ("Erhalte Stream" + filename);
											}
										
										server.send(200, "text/plain", "");
										*/

// Here i need a hint, because all the Examples are with sending a file from a form. Not getting it directly from the php scipt.
										
										
										
									}
									
						
									
								} else
									log ("SPIFFS Files sind nicht vorhanden!");
					
							} else 
								log ("Number of Spiffs ERROR: " + numberofspiffs);
	
						} else
							log ("Version ist aktuell. Kein Update erforderlich.");		  
										
					} else
						log ("Fehler beim Updateserver: " + httpClient.errorToString(httpCode));

Thanks for helping! If you need more Code or have any question, pls ask.

OK. A new day. New Motivation.

The solution is really easy:

Just adding the SPIFFS.bin to my Server and run:

t_httpUpdate_return ret = ESPhttpUpdate.updateSpiffs( [url] );