If the server supports ftp access you can upload it using the starage system in laravel https://laravel.com/docs/9.x/filesystem#ftp-driver-configuration
Feb 15, 2023
6
Level 2
Upload file from one server to another server
Hello everyone, I need help on below issue. Actually the php file in one server (/home/phm/domains/phm.com.my/public_html/lpi_offline_pdf) but I would like to upload the file (/home/mxm/domains/mxm.com.my/public_html/system/public/lpi_offline_pdf/pdf) in another server. I have tried such as $sftpServer = "IP Address or Hostname of SFTP Server", $sftpDestPort = "22", $sftpRemotePath = "/", $sftpUsername = "sftp_user" but its not working. It's confused to assign the $uploadFileDir to another server. can anyone help me on this. (⌣́_⌣̀)
$uploadFileDir = './pdf/' . $nric . '/' . $policy_expiry_year . '/';
if (!file_exists($uploadFileDir)) {
mkdir($uploadFileDir, 0777, true);
}
$dest_path_s = $uploadFileDir . $new_file_name_s;
$dest_path_i = $uploadFileDir . $new_file_name_i;
$dest_path_r = $uploadFileDir . $new_file_name_r;
if (move_uploaded_file($fileTmpPath_i, $dest_path_i))
$i_flag = true;
if (move_uploaded_file($fileTmpPath_s, $dest_path_s))
$s_flag = true;
if (move_uploaded_file($fileTmpPath_r, $dest_path_r))
$r_flag = true;
if ($i_flag && $s_flag && $r_flag) {
$query_update = $db->query("UPDATE lpi_offline_pdf_upload_log SET latest_record = 0 WHERE latest_record = 1 AND policy_master_id = $policy_master_id;");
$query_insert = $db->query("INSERT INTO lpi_offline_pdf_upload_log (t_policy_no,policy_master_id,creation_date) VALUES ('$policy_no',$policy_master_id,NOW())");
echo '<script> success_toastr(); </script>';
} else {
echo '<script> toastr.error("File upload failed.","Fail"); </script>';
}
Level 102
@Tharshini_95 laravel supports that as well. No need for an external library :) https://laravel.com/docs/9.x/filesystem#sftp-driver-configuration
1 like
Please or to participate in this conversation.