Yii Framework Forum: How to transfer file(s) to another server - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to transfer file(s) to another server [canceled]

#1 User is offline   tklustig 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 400
  • Joined: 20-April 17
  • Location:Hannover

Posted 21 December 2017 - 09:37 AM

Hi guys, following code will transfer files into local filesystem of Webserver. It is also possible,tranfering this file to another ftp-server. What about transfering files(s) to another Webserver. Is there any possibility transfering files to another webserver. Actually,I will get error:

fopen(http://tklustig.ddns.net:1025/img/woman_2.jpg): 
failed to open stream: HTTP wrapper does not support writeable connections


That's way, I upload files to another ftp-server.I am not using any ftp-extension by now

$server="";
$ftp_user_name="";
$ftp_user_pass="";
$dest="";
$source="";
$mode="FTP_ASCII";
$connection = ftp_connect($server);
$login = ftp_login($connection, $ftp_user_name, $ftp_user_pass);
if (!$connection || !$login) { die('Connection attempt failed!'); }
$upload = ftp_put($connection, $dest, $source, $mode);
if (!$upload) { echo 'FTP upload failed!'; }
ftp_close($connection);




Here is code, which 'causes error:

   	if ($model->loadAll(Yii::$app->request->post()) && $model_eingang->loadAll(Yii::$app->request->post())) 
            $model->attachement = UploadedFile::getInstances($model, 'attachement');
            $bez = "E-Mail-Anhang";
            $bez_error = "kein Fehler aufgeteten"
 			$anhangszaehler = 0;
            $anhang = array();
            if ($model->upload()) {
                $folder_read = Yii::getAlias('@uploading/');[
                $folder_write = Yii::getAlias('@emailanhang');
                $upload_copy = opendir($folder_read);
                while ($file = readdir($upload_copy)) {
                    if ($file != "." && $file != ".." && $file != ".gitkeep" && $file != ".gitignore") {
                        copy($folder_read . $file, $folder_write . $file);
                        $folder_http = "http://tklustig.ddns.net:1025/img/";
                        fopen($folder_http.$file,"w"); //this will cause error
                        copy($folder_read . $file, $folder_http . $file);//this will cause error as well
                        $anhang[$anhangszaehler] = $file;
                        $anhangszaehler++;
           		}
                }
.
.
.

0

#2 User is offline   alrazi 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,546
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 22 December 2017 - 05:10 AM

I would recommend you upload the files to you local server and run a background process perhaps even a cron job that moves these files to your remote server won't recommend you do this in your request process it will kill your application.
0

#3 User is offline   tklustig 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 400
  • Joined: 20-April 17
  • Location:Hannover

Posted 28 December 2017 - 04:16 AM

View Postalrazi, on 22 December 2017 - 05:10 AM, said:

I would recommend you upload the files to you local server and run a background process perhaps even a cron job that moves these files to your remote server won't recommend you do this in your request process it will kill your application.


Why this. Here is code,which will solve my problem. I don't understand,why this code could kill my application....
.
.

[size=3]                try {

[size=3]     			$model_folder = Dateianhang::find()[/size]
[size=3]                                    ->join('LEFT JOIN', 'e_dateianhang', 'e_dateianhang.id=dateianhang.id_e_dateianhang')[/size]
[size=3]                                    ->where(['id_mail_ausgang' => $id])->one();                    
				$folder = AppEinstellung::getSpeicherOrt($model_folder);
[size=3]                    $extract_outer = explode("'", $folder);
[size=3]                    $extract_inner = explode(";", $extract_outer[0]);
[size=3]                    $host = $extract_inner[0];
[size=3]                    $username = $extract_inner[1];
[size=3]                    $password = $extract_inner[2];
[size=3]                    $folder_ftp = $extract_inner[3];
[size=3]                    $ftp->connect($host);
[size=3]                    $ftp->login($username, $password);
[size=3]                    $upload_ftp = opendir($folder_read);
[size=3]                    while ($file = readdir($upload_ftp)) {
[size=3]                        if ($file != "." && $file != ".." && $file != ".gitkeep" && $file != ".gitignore") {
[size=3]                            if (preg_match($jpg, $file))
[size=3]                                $mode = FTP_BINARY;
[size=3]                            else
[size=3]                                $mode = FTP_ASCII;
[size=3]                            $ftp->put($folder_ftp . $file, $folder_read . $file, $mode);
[size=3]                        }
[size=3]                    }
[size=3]                    closedir($upload_ftp);
[size=3]                } catch (\Exception $error) {
[size=3]                    $session->addFlash("info", "Die Konfigurationsparameter Ihres FTP-Servers sind inkorrekt.Die E-Mail wurde folglich nicht versandt.Bitte informieren Sie Ihren Admin!");
[size=3]                    return $this->redirect(['index']);
}
.
.

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users