เรื่องก็คือว่าผมต้องการ ftp ด้วยสคริปต์ php ซึ่งผมก็ลองไปค้นหาจากพี่ Goo (Google) แล้วก็ใช้ได้ปกติถ้า ftp ผ่านฟอร์ม
และผู้ใช้เป็นคนเลือกไฟล์จากในเครื่องตัวเองขึ้นไปนะครับ
แต่คราวนี้ที่ผมต้องการคือว่าผมอยากจะให้มันเป็นแบบอัตโนมัิติ คือทำการ ftp ไฟล์จาก host A ไปใส่ host B โดยไม่ต้อง
ผ่านฟอร์มหน่ะครับ
ปัญหาก็คือ ผมไม่รู้ว่าจะเรียกหา path ไฟล์หรือเก็บค่าไฟล์ใน host A ไว้ในตัวแปรอย่างไร ก่อนจะทำการ ftp ส่งเข้า host B
ครับ ตัวอย่างปัญหานะครับ
ที่ Host A ผมเก็บไฟล์ที่ต้องการ ftp ไว้ที่ landingpage/test.php
ที่ Host B ผมแค่ต้องการเอาไฟล์ test.php ขึ้นไปไว้ใน root ก็ได้แล้วครับ
นี่คือตัวสคริปที่ผมทดสอบแบบ ftp ผ่านฟอร์มได้ปกติครับ
<?php
if($upload){
//change these values to suit your site
$ftp_user_name='ssmk';
$ftp_user_pass='111111';
$ftp_server='ftp.domain.com';
$ftp_dir='domain.com/';
//$web_location is needed for the file_exists function, the directories used by FTP
$web_dir='doman.com/';
$web_location=$web_dir.$imagefile_name;
//build a fully qualified (FTP) path name where the file will reside
$destination_file=$ftp_dir.$imagefile_name;
// connect, login, and transfer the file
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
$upload = ftp_put($conn_id, $destination_file, $imagefile, FTP_BINARY);
ftp_close($conn_id);
//verify file was written
if (file_exists($web_location))
{
echo "file was uploaded as $web_location";
}
else
{
echo "Could not create $web_location";
}
//end if
}
//prepare a form similiar to this and have it call the below file
echo '<form action="ftp.php" method="post" enctype="multipart/form-data">';
echo 'Click the Browse button to find the file you wish to upload';
echo '<input type="file" name="imagefile">';
echo '<INPUT TYPE="submit" name="upload" value="upload">';
echo '</form>';
?>
ผมอยากขอความช่วยเหลือว่า ถ้าไม่เอาฟอร์มแต่ไปดึงไฟล์จากใน host A เลยตรงค่า $imagefile จะรับมาอย่างไรดีครับ
ขอบคุณทุกท่านมากครับ
