Having trouble uploading a file
- by neo skosana
Hi
I am having trouble uploading a file. First of all I have a class:
class upload
{
private $name;
private $document;
public function __construct($nme,$doc)
{
$this->setName($nme);
$this->setDocument($doc);
}
public function setName($nme)
{
$this->name = $nme;
}
public function setDocument($doc)
{
$this->document = $doc;
}
public function fileNotPdf()
{
/* Was the file a PDF? */
if ($this->document['type'] != "application/pdf")
{
return true;
}
else
{
return false;
}
}
public function fileNotUploaded()
{
/* Make sure that the file was POSTed. */
if (!(is_uploaded_file($this->document['tmp_name'])))
{
return true;
}
else
{
return false;
}
}
public function fileNotMoved($repositry)
{
/* move uploaded file to final destination. */
$result = move_uploaded_file($this->document['tmp_name'],
"$repositry/$this->name.pdf");
if($result)
{
return false;
}
else
{
return true;
}
}
}
Now for my main page:
$docName = $_POST['name'];
$page = $_FILES['doc'];
if($_POST['submit'])
{
/* Set a few constants */
$filerepository = "np";
$uploadObj = new upload($docName, $page);
if($uploadObj->fileNotUploaded())
{
promptUser("There was a problem uploading the file.","");
}
elseif($uploadObj->fileNotPdf())
{
promptUser("File must be in pdf format.","");
}
elseif($uploadObj->fileNotMoved($filerepository))
{
promptUser("File could not be uploaded to final destination.","");
}
else
{
promptUser("File has been successfully uploaded.","");
}
}
The errors that I get:
Warning: move_uploaded_file(about.pdf)[function.move-uploaded-file]: failed to open stream: No such file or directory in...
Warning: move_uploaded_file()[function.move-uploaded-file]: Unable to move 'c:\xampp\tmp\php13.tmp' to 'about.pdf' in...
File could not be uploaded to final destination.