re: [PHP] FTP upload in PHP4
| From: | John Damask | Date: | Tue, 31 Oct 2000 18:48:20 +0000 |
| Subject: | re: [PHP] FTP upload in PHP4 | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-22984@lists.php.net to get a copy of this message | ||
Vikram
First, make your form 'method=post' instead of Get.
You will want to access your uploaded files using $HTTP_POST_FILES global
array. This array is not quite documented but you can find info in the
manual by searching for 'upload'.
Read the section on Post Method Uploads.
You'll want to copy the file from the temp upload directory to your new
location (or FTP as is your case).
On a Linux box that uses the system temp directory, we can copy the file
like so:
Assume we've uploaded an image from form field: 'f_images_r'
<?
$HF = $HTTP_POST_FILES;
// This line finds the temp file
$uploadpath = dirname(tempnam('', '')) . '/' .
basename($HF["f_images_r"]["tmp_name"][$i]);
// This line is where we want the file copied
$cppath = $dir . "/" . basename($HF["f_images_r"]["name"][$i]);
copy ("$uploadpath", $cppath);
?>
I haven't done this using FTP but I guess you use your FTP connect string in
place of my $ccpath and use the function ftp_put() instead of copy()
hope this helps
John
---------------------------------------------------------------------
Hi!
I'm trying to create a form which selects a file and then uploads it via
FTP to an FTP server. Can someone help me out with the front-end code for
the form, and with the PHP script?
Here's what I've got so far:
<form action=ftput.php4 method=get>
Upload this file:<input type=file name=filen>
<input type=hidden name=server value=<? echo $server; ?>>
<input type=hidden name=username value=<? echo $username; ?>>
<input type=hidden name=password value=<? echo $password; ?>>
<input type=submit>
</form>
And in ftput.php4:
<?
$result = ftp_connect($server);
ftp_login($result, $username, $password);
$a = ftp_put($result, $filen, $filen, FTP_BINARY);
?>
TIA
Vikram