-
October 10th, 2004, 07:47 PM
#1
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:
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?
A mind full of questions has no room for answers
-
October 10th, 2004, 08:02 PM
#2
I think you have to give the full path, like...
/home/user/public_html/records/
and also, make sure there are write permissions on that directory for whatever is going to need to write to it. Peace.
-
October 10th, 2004, 09:41 PM
#3
I changed the path to the full path and the permissions are fine, the temp is 1777 and the records file is 0755, I've also tried using copy() but it's still not running
A mind full of questions has no room for answers
-
October 10th, 2004, 11:29 PM
#4
is the records directory owned by the webserver? I think that's the only way you will be able to write to it with 755 perms. Other than that, just fool around with it a whole bunch. That's what programming is.
-
October 12th, 2004, 01:54 AM
#5
I found the trouble
The file that i was copying had correct permissions, but the folder i was trying to copy the file to only allowed read and write, i needed exec to copy the file
A mind full of questions has no room for answers
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|