01.
<?php
02.
03.
if
(
$_POST
[
'submit'
]){
04.
set_time_limit(3000);
05.
06.
$ftp_server
=
"www.test.co.th"
;
07.
$ftp_user_name
=
"test"
;
08.
$ftp_user_pass
=
"pass"
;
09.
$destination_file
=
'/file/'
.
$_FILES
[
'file'
][
'name'
];
10.
$source_file
=
$_FILES
[
'file'
][
'tmp_name'
];
11.
$size_file
=
$_FILES
[
'file'
][
'size'
];
12.
$conn_id
= ftp_connect(
$ftp_server
);
13.
14.
15.
$login_result
= ftp_login(
$conn_id
,
$ftp_user_name
,
$ftp_user_pass
);
16.
17.
ftp_chdir(
$conn_id
,
'/httpdocs/demo/file'
);
18.
19.
if
((!
$conn_id
) || (!
$login_result
)) {
20.
echo
"FTP connection has failed!"
;
21.
echo
"Attempted to connect to $ftp_server for user $ftp_user_name"
;
22.
exit
;
23.
}
else
{
24.
echo
"Connected to $ftp_server, for user $ftp_user_name<br/>"
;
25.
}
26.
27.
$upload
= ftp_put(
$conn_id
,
$destination_file
,
$source_file
, FTP_BINARY);
28.
29.
if
(!
$upload
) {
30.
echo
"FTP upload has failed!"
;
31.
}
32.
33.
ftp_close(
$conn_id
);
34.
35.
}
36.
?>
37.
<form action=
""
method=
"POST"
enctype=
"multipart/form-data"
>
38.
<table align=
"center"
>
39.
<tr>
40.
<td align=
"right"
>
41.
Select your file to upload:
42.
</td>
43.
<td>
44.
<input name=
"file"
type=
"file"
size=
"50"
>
45.
</td>
46.
</tr>
47.
</table>
48.
<table align=
"center"
>
49.
<tr>
50.
<td align=
"center"
>
51.
<input type=
"submit"
name=
"submit"
value=
"Upload image"
/>
52.
</td>
53.
</tr>
54.
55.
</table>
56.
</form>