note 77877 added to ref.ftp
| From: | dotadot at dotdotcom | Date: | Tue, 18 Sep 2007 03:49:42 +0000 |
| Subject: | note 77877 added to ref.ftp | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130559@lists.php.net to get a copy of this message | ||
This took me a few hours to work out. It is based on the code below I've just added a string
replace to convert pathname given by Windows to Unix pathname. Hope it saves somebody some time.
Enjoy! (Also, delete file function is included:))
<?php
$myFile = $_FILES['file']; // This will make an array out of the file information that was
stored.
$file = $myFile['tmp_name']; //Converts the array into a new string containing the path
name on the server where your file is.
$myFileName = $_POST['MyFile']; //Retrieve file path and file name
$myfile_replace = str_replace('\\', '/', $myFileName); //convert path for use
with unix
$myfile = basename($myfile_replace); //extract file name from path
$destination_file = "/".$myfile; //where you want to throw the file on the webserver
(relative to your login dir)
// connection settings
$ftp_server = "127.0.0.1"; //address of ftp server (leave out ftp://)
$ftp_user_name = ""; // Username
$ftp_user_pass = ""; // Password
$conn_id = ftp_connect($ftp_server); // set up basic connection
// login with username and password, or give invalid user message
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("<h1>You do
not have access to this ftp server!</h1>");
$upload = ftp_put($conn_id, $destination_file, $file, FTP_BINARY); // upload the file
if (!$upload) { // check upload status
echo "<h2>FTP upload of $myFileName has failed!</h2> <br />";
}
/*
// try to delete $file
if (ftp_delete($conn_id, $destination_file)) {
echo "$destination_file has been deleted!\n";
} else {
echo "Could not delete $destination_file!\n";
}
*/
ftp_close($conn_id); // close the FTP stream
}
?>
<form name="form" enctype="multipart/form-data" action="<?php echo
$_SERVER['PHP_SELF']; ?>" method="POST" >
Please choose a file: <input type="file" name="file"
accept="text/plain" onChange="MyFile.value=file.value">
<input name="MyFile" type="hidden" id="MyFile"
tabindex="99" size="1" />
<input type="submit" name="submit" value="upload"
style="vertical-align:middle"/><br/><br/>
</form>
----
Server IP: 203.16.234.19
Probable Submitter: 58.169.65.137
----
Manual Page -- http://www.php.net/manual/en/ref.ftp.php
Edit -- https://master.php.net/note/edit/77877
Del: integrated -- https://master.php.net/note/delete/77877/integrated
Del: useless -- https://master.php.net/note/delete/77877/useless
Del: bad code -- https://master.php.net/note/delete/77877/bad+code
Del: spam -- https://master.php.net/note/delete/77877/spam
Del: non-english -- https://master.php.net/note/delete/77877/non-english
Del: in docs -- https://master.php.net/note/delete/77877/in+docs
Del: other reasons-- https://master.php.net/note/delete/77877
Reject -- https://master.php.net/note/reject/77877
Search -- https://master.php.net/manage/user-notes.php