move_uploaded_file failed to open stream: No such file or directory

Asked

Viewed 1,578 times

0

When I send a photo to update the profile on the system, it returns the following failure: move_uploaded_file(/isequi/public/Assets/img/user_pic/062701-20160807-suicidal.jpg): failed to open stream: No such file or directory in C: xampp htdocs isequi sys class user.php

The test environment is windows 7 with xampp.

Code used:

$this->picName = basename($_FILES['userPicture']['name']); 
        $this->picExtension = pathinfo($this->picName, PATHINFO_EXTENSION); 
        $this->picSize = round($_FILES['userPicture']['size'] / 1000); 

        if($this->picSize == 0) {
            $functions -> generateJsonMsg('selectPicture', null, null, null, $message->message['selectPicture']);
        }
        if($this->picSize > 100)    {
            $functions -> generateJsonMsg('fileIsTooLarge', null, null, null, $message->message['fileIsTooLarge']);
        }
        $functions -> isInArray($this->picExtension, $this->arrayPictureExtensionPermitted, 'extensionNotAllowed', $message->message['extensionNotAllowed']);   

        $this->picName = date('sih-Ymd').'-'.$this->picName;
        $this->picNameDirectory = '/webpage/public/assets/img/user_pic/'.$this->picName;

        if(move_uploaded_file($_FILES['userPicture']['tmp_name'], $this->picNameDirectory)) {
            try   {
                $this->conn = parent::getconnection();  
                $this->pQuery = $this->conn->prepare(   'update user_detail '.
                                                        'set ud_picture=:picName '.
                                                        'where fk_user_id=:sessionId '.
                                                        'limit 1'   );  
                $this->pQuery->execute(array(   ':picName' => $this->picName, 
                                                ':sessionId' => $session -> sessionId()     ));
                if($this->pQuery->errorCode() == 0) {
                    $functions -> generateJsonMsg('success', null, null, null, $message->message['iconSuccess']);
                }   
                else     {
                    throw new Exception();
                }                               
            }
            catch(Exception $e) {
                $tException = new tException();
                $tException -> newException($e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString());
            }   
        }
  • Are you sure that the one you want to delete is the one that was there before the update and that file exists in the path indicated in the error?

  • I did a test inserting an echo using $_FILES['userPicture']['tmp_name'] and checked if the temp file was there, and did not find the.tmp file. The Directive in question /webpage/public/Assets/img/user_pic/ exists

  • That is not what you have to see, in the case of the question you would have to see whether 062701-20160807-suicida.jpg exists in /isequi/public/assets/img/user_pic/

  • This is Miguel.. The file was not created in the folder. I changed the folder’s permission, but it keeps giving the same fault.

  • It’s not the permissions problem. No such file or directory in ... is because there is no /062701-20160807-suicida.jpg or the way is wrong

2 answers

1

Since it is Windows try to put the absolute path, for example:

C:/folder/where/Voce/will/save/

Also, check that this folder has full permission (0777)

The error that returned to you "failed to open stream: No such file or directory" says that the directory could not be opened, that is, it does not exist.

  • I didn’t change permission in the folder, I just changed the User Account Control to notify when you have any changes. I searched a lot before posting the doubt, to see if there is any configuration in xampp or windows and found nothing configuration for these.

  • Thanks Alisson. I put the absolute path and it worked.

0

Apparently the error is not in the code snippet you passed, where is called your function? You are giving an error is in the User Class; probably a class that does not exist in the repository is being instantiated.

  • There is a Jquery call for the method called changePicture.php, this belongs to the user class.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.