Josiah
Josiah

Reputation: 83

Upload file doesn't save to specify folder, throw error

The error is Warning: move_uploaded_file(uploads/cv/23456543555555CURRICULUM VITAE.doc): failed to open stream: No such file or directory in C:\wamp\www\job-application\include\application.class.php on line 121

Warning: move_uploaded_file(): Unable to move 'C:\wamp\tmp\php7EA1.tmp' to 'uploads/cv/23456543555555CURRICULUM VITAE.doc' in C:\wamp\www\job-application\include\application.class.php on line 121

The code follows below;

$allowedExtsDoc = array("docx", "pdf", "doc");
            $temp = explode(".", $_FILES["file"]["name"]);
            $extensionDoc = end($temp);
            $uploaddircv = 'uploads/cv/';
            $uploadfilecv = $uploaddircv . basename($phone.$_FILES['file']['name']);
            if (in_array($extensionDoc, $allowedExtsDoc))
                {
                    if ($_FILES["file"]["error"] > 0)
                    {
                        $this->error .= $_FILES["file"]["error"] . "<br>";
                    }
                    else
                    {   
                        if (file_exists($uploaddircv . $_FILES["file"]["name"]))
                        {
                            $this->error .= $_FILES["file"]["name"] . " already exists. <br/>";
                        }
                        else
                        {
                            move_uploaded_file($_FILES["file"]["tmp_name"],$uploadfilecv);
                            $fileloc = $this->sitePath.$uploadfilecv;
                        }
                    }
                }
            else
            {
                $this->error .= "Invalid file <br/>";
            }

Upvotes: 0

Views: 157

Answers (1)

lucasvscn
lucasvscn

Reputation: 1230

Make sure the directories: C:\wamp\tmp\ and uploads/cv/ exists and are writable by Apache.

After that, try to use the complete path to uploads folder.

$uploaddircv = realpath(dirname(__FILE__) . '/../uploads/cv/') . '/';

Upvotes: 2

Related Questions