In web-based system evolution, sometimes we demand a characteristic to upload a file or document in addition to supporting the information processed on the organisation. This is inseparable from the file upload characteristic which is implemented into the system. As we know that the file storage can be placed in a special folder inside or under the root folder. But sometimes there are some cases or conditions, where we need to upload the file on another server, for example, a special server for important documents. There are also weather when the website owner or admin wants to dissever static files (images, upload files, other web assets) with the core plan and then that it does not bear upon the functioning of the core program.

When nosotros find this case, of form, we tin use the FTP role in PHP to upload files to the remote server. But sometimes website owners or admins don't want to open or utilise multiple ports in cases like this for server security reasons. Hither I am trying to draw i of the information transmission techniques using the Ringlet function bachelor in PHP.

By default, the Ringlet module package is bachelor in PHP. However, in that location are several installation program packages that do not include Curlicue in their PHP packages. Here yous don't need to worry, because you can install information technology yourself. Previously, brand certain that the CURL module bundle is already installed in your PHP. You can cheque it on phpinfo.

<?php // save the file with the name phpinfo.php phpinfo(); ?>                

If the curl module is not already activated, you can merely activate it past opening the php.ini configuration file and looking for this line:

; extension = php_curl.dll

And so remove the semicolon sign to exist like this:

extension = php_curl.dll

So save and restart the apache service.

After successfully installing the Gyre module, we now try to create a file to send the file. This file volition be placed on server A (Example: 192.168.106.11/app). Name it form_upload.php.

<?php // salve the file with the name form_upload.php function upload_file_remote_server($upload_file, $upload_url, $upload_filename){ 	$postfields = array(); 	$postfields['nama_file'] = $upload_filename;  	if (isset($upload_file['name'])) { 		 		if (function_exists('curl_file_create')) { // For PHP 5.5+ 			$postfields["upload_file"] = curl_file_create( 				$upload_file['tmp_name'], 				$upload_file['type'], 				$upload_file['name'] 			); 			 		} else { 			$postfields["upload_file"] = '@' . $upload_file['tmp_name'] 												  . ';filename=' . $upload_file['proper noun'] 												  . ';type='     . $upload_file['type']; 		} 	} 	 	$ch         = curl_init(); 	$headers    = assortment("Content-Type:multipart/course-information");  	curl_setopt_array($ch, array( 		CURLOPT_POST            => i, 		CURLOPT_URL             => $upload_url, 		CURLOPT_RETURNTRANSFER  => 1, 		CURLINFO_HEADER_OUT     => 1, 		CURLOPT_HTTPHEADER      => $headers, 		CURLOPT_POSTFIELDS      => $postfields 	)); 	 	$result = curl_exec($ch); 	 	if (curl_errno($ch)) { 		$error_msg = curl_error($ch); 		echo $error_msg; 		exit(); 	}  	curl_close ($ch); }  if($_FILES){ 	 	$temp 	= explode(".", $_FILES['surat']['name']); 	$surat 	= 'FILE_'.date('YmdHis').terminate($temp);	 	 	// SAVE TO REMOTE SERVER 	$upload_file    = $_FILES['surat']; 	$upload_url     = "http://192.168.106.xiii/files/upload_to_server.php"; 	$upload_filename= $surat; 	 	upload_file_remote_server($upload_file, $upload_url, $upload_filename); 	 	// Salve TO LOCAL SERVER 	$destination 	= "./uploads/" . $surat; 	move_uploaded_file($_FILES['surat']['tmp_name'], $destination); 	 	echo 'Uploaded!'; 	go out(); }  echo '<form method="POST" action="?" enctype="multipart/grade-information"> 		<input type="file" name="surat" required> 		<input type="submit" value="Upload" name="upload"> 	</class>'; ?>                

Next, create a file to have it's upload parameters. This file is located on server B (Example: 192.168.106.13/files). Name it upload_to_server.php.

<?php // relieve the file with the name upload_to_server.php $path_target 	= ''; $nama_file 		= ($_POST['nama_file'] ? $_POST['nama_file'] : date('YmdHis')); $upload_file 	= (isset($_FILES['upload_file'])) ? $_FILES['upload_file'] : assortment(); $count 			= 0;  if (isset($upload_file['name'])) { 	 	if ($upload_file['error'] == 0) { 		$path_target= ($path_target == '' ? '' : $path_target . '/'); 		$path 		= "./uploads/".$path_target; 		$name_file 	= $path . $nama_file; 		 		if (@move_uploaded_file($upload_file["tmp_name"], $name_file)) { 			$count++; // TOTAL SUCCESS FILE UPLOADED 		} 	} }  echo 'Uploaded: '.$count.' file(south)'; ?>                

The code above is a modification of some of the references that I got. I got it through this link, this, and this. I am very grateful if you tin provide the best input if you have a simple way in the case above. Thank you very much for visiting this commodity.