Having problems uploading files in PHP
Results 1 to 5 of 5

Thread: Having problems uploading files in PHP

  1. #1
    Senior Member
    Join Date
    Dec 2003
    Location
    LA, CA
    Posts
    292

    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

  2. #2
    Elite Hacker
    Join Date
    Mar 2003
    Posts
    1,407
    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.

  3. #3
    Senior Member
    Join Date
    Dec 2003
    Location
    LA, CA
    Posts
    292
    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

  4. #4
    Elite Hacker
    Join Date
    Mar 2003
    Posts
    1,407
    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.

  5. #5
    Senior Member
    Join Date
    Dec 2003
    Location
    LA, CA
    Posts
    292
    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
  •