Having problems uploading files in PHP
Hello all,
I've got a problem with a script i'm working on. I'm attempting to upload a file and data used to index the file. The errors i'm gettings are:
Quote:
Warning: move_uploaded_file(/public_html/records/Babbage_engine.jpg): failed to open stream: No such file or directory in /home/towerpub/public_html/config/admintasks.inc on line 349
Warning: move_uploaded_file(): Unable to move '/tmp/php2vb2MO' to '/public_html/records/Babbage_engine.jpg' in /home/towerpub/public_html/config/admintasks.inc on line 349
Warning: chmod(): No such file or directory in /home/towerpub/public_html/config/admintasks.inc on line 350
The section of code causing problems:
Code:
function addsubmit()
{
// load html file
$this->display = new Template();
$this->display->set_file("page", "htmltemplates/addsubmit.html");
$this->display->set_block("page", "block", "main");
$this->filepath = "/public_html/records/" . $_FILES[addfile][name];
$this->recorddesc = $_POST['desc'];
// check for all fields
if(($_POST['injury'] == "NEW") && (is_null($_POST['newinjury'])))
{
// missing new injury
$this->displaytext = "Form missing new injury";
}
elseif (is_null($_POST['desc']))
{
// missing description
$this->displaytext = "Form missing description";
}
elseif (is_null($_FILES['addfile']))
{
// missing file
$this->displaytext = "Form missing file";
}
elseif (file_exists($this->filepath))
{
// bad file name
$this->displaytext = "File name already exists";
}
else
{
if ($_POST['injury'] == "NEW")
{
$this->injury = $_POST['newinjury'];
}
else
{
$this->injury = $_POST['injury'];
}
chmod($_FILES['addfile']['tmp_name'], 0755);
move_uploaded_file($_FILES['addfile']['tmp_name'], $this->filepath);
chmod($this->filepath, 0755);
// connect to database
$this->connection = mysql_connect($this->dblocation, $this->dbname, $this->dbpass) or die(mysql_error());
$this->dbsel = mysql_select_db($this->database, $this->connection) or die(mysql_error());
// add record
$this->sql = "insert into records VALUES (NULL, '$this->recorddesc', '$this->filepath', '$this->injury')";
$this->result = mysql_query($this->sql, $this->connection) or die(mysql_error());
$this->displaytext = "Record Added <br> Injury: $this->injury <br> $this->recorddesc";
}
$this->display->set_var("message", $this->displaytext);
$this->display->parse("main", "block", FALSE);
$this->display->pparse("OUT", "page");
exit;
}
Anyone see the problem?