|
Posted by Steve Turnbull on 03/07/05 23:05
Hi
I have tried creating a script which will allow our core staff to upload
files to our FTP server.
I don't have a problem with the uploading of a local file to our FTP server
with the correct authentication etc, the problem I am having, is that the
file which gets uploaded always has the filename of 'www.ourdomain.net'
which is the destination web server name.
I have a form, which has a file 'browse' element. PHP stores the local file
in /tmp/ as with a temporary file name (I can see this with
$_FILES['$file']['tmp_name']), but I don't know why it gets converted to
'www.ourdomain.net' in the final stages?
My code (rough, but you get the idea);
Thanks for any help
Steve
<?php>
$ftp_server = '<OUR FTP SERVER>';
$un = $_REQUEST['ftp_un'];
$pw = $_REQUEST['ftp_pw'];
$tmp_file = $_FILES['ftp_f']['tmp_name'];
$file = $_FILES['ftp_f']['name'];
?>
<html>
<head>
<title>FTP Interface</title>
</head>
<body>
<div id="topHeader">
<h1>FTP Interface</h1></td>
</div>
<?php
if (is_null($file)) {
?>
<div>
You need a username & password to upload files to the FTP area.<br /><br />
<form enctype="multipart/form-data" action="<?php echo $_SERVER
['PHP_SELF'] ?>" method="post">
<div>
<span>Username: </span>
<span style="position:absolute; left:150px;"><input type="text"
name="ftp_un" /></span>
</div>
<div>
<span>Password: </span>
<span style="position:absolute; left:150px;"><input type="password"
name="ftp_pw" /></span>
</div>
<div>
<span>Browse for file: </span>
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<span style="position:absolute; left:150px;"><input type="file"
name="ftp_f" /></span>
</div>
<div>
<input type="submit" value="Upload File Now" />
</div>
</form>
</div>
<?php
}
else {
$c = ftp_connect($ftp_server, 21) or die("Can't connect");
if (!ftp_login($c, $un, $pw)){
echo 'Login details incorrect, please try again...';
} else {
if (ftp_put($c, $ftp_server, $tmp_file, FTP_ASCII)){
ftp_rename($c, "<OUR FTP SERVER>", $file) or die("ftp rename didn't
work");
echo 'your file has transfered successfully!';
} else {
echo 'There was a problem, please retry...';
}
}
ftp_close($c);
}
?>
<body>
</html>
[Back to original message]
|