jordanking
Programmer
- Sep 8, 2005
- 351
hello,
I am attempting to create a page that retrieves a text file for updating by the user. I have no problem retireving and placing the contents of a text file within a user form. This idea is that the user then changes some or all of the text and when they push the update button the content of the form overwrites the existing text file.
the problem I am getting is that the code breaks at fopen function. here is my code.
the following is the exact error
I know that the user name and password are right because when i use them on any other ftp manager it works and grants me full permission. Also, I am able to read the file without a problem. I am not very familiar with php's ftp functions so I might be missing something obvious.
Any ideas?
Thank in advance
I am attempting to create a page that retrieves a text file for updating by the user. I have no problem retireving and placing the contents of a text file within a user form. This idea is that the user then changes some or all of the text and when they push the update button the content of the form overwrites the existing text file.
the problem I am getting is that the code breaks at fopen function. here is my code.
Code:
<?php
$error = array();
$f_error = array();
$f_contents = array();
$success = array();
// initiate session
if (!isset($_SESSION)) {
session_start();
}
// check that the form has been submitted and that name and password match required values
if ($_SESSION && $_SESSION['user']=='********' && $_SESSION['pwd']=='*********'){
} else {
header("Location: ../admin/login_fail.php");
exit();
}
$MM_flag="MM_update";
if (isset($_POST[$MM_flag])) {
// user input validation rotines here
// ensure content is not empty and format for html
if (empty($_POST['content'])) {
$error['content'] = 'Please enter text for content';
} else {
$content = nl2br(trim($_POST['content']));
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (!$error) {
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "admin")) {
// this will open an ftp connection and read the file into memory
$ftp_server = "[URL unfurl="true"]www.c3metro.ca";[/URL]
$ftp_user = "*********";
$ftp_password = "********";
$destination_directory = "text/";
$destination_file = "history.txt";
// set up a connection
$conn_id = ftp_connect($ftp_server);
// login to ftp
$login_result = ftp_login($conn_id, $ftp_user, $ftp_password);
// set passive
$set_passive = ftp_pasv($conn_id, true);
// set timeout
$set_timeout = ftp_set_option($conn_id, FTP_TIMEOUT_SEC, 300);
// set up variables
//open file for writing
$f_handle = fopen('../text/history.txt', 'w+');
if ($f_handle) {
// This will write to the start of the file
fwrite($f_handle, $content);
// close the files
fclose($f_handle);
} else {
$f_error['file'] = "File failed to open";
}
// close connection
ftp_close($conn_id);
}
}
the following is the exact error
Code:
Warning: fopen("../text/test2.txt", "w") - Permission denied in D:\Websites\[URL unfurl="true"]www.c3metro.ca\admin\admin.php[/URL] on line 49
File failed to open
I know that the user name and password are right because when i use them on any other ftp manager it works and grants me full permission. Also, I am able to read the file without a problem. I am not very familiar with php's ftp functions so I might be missing something obvious.
Any ideas?
Thank in advance