The second argument to copy() function cannot be a directory

后端 未结 7 790
温柔的废话
温柔的废话 2020-12-18 20:29

Anyone know why this:



        
相关标签:
7条回答
  • 2020-12-18 20:45

    Try adding the extension to the name file.

    $filename = $_FILES['userfile']['tmp_name'].".jpg";
    
    0 讨论(0)
  • 2020-12-18 20:49

    Because PHP is not a shell. You're trying to copy the file into the c:\wamp\www\uploads\images directory, but PHP doesn't know you mean that when you execute (within the move_uploaded_file function):

    copy($_FILES['userfile']['tmp_name'], 'c:\wamp\www\uploads\images/');
    

    This command tells it to rename the file to c:\wamp\www\uploads\images/, which it can't do because that's the name of an existing directory.

    Instead, do this:

      move_uploaded_file($_FILES['userfile']['tmp_name'], 
        'c:\wamp\www\uploads\images/' . basename($_FILES['userfile']['tmp_name']));
    
    0 讨论(0)
  • 2020-12-18 20:53

    It's because you're moving a file and it thinks you're trying to rename that file to the second parameter (in this case a director).

    it should be:

    move_uploaded_file($_FILES['userfile']['tmp_name'], 'c:/wamp/www/uploads/images/'.$file['name']);
    
    0 讨论(0)
  • 2020-12-18 20:57

    if you want just copy the file in two Dir different, try this :

    if (move_uploaded_file($_FILES['photo']['tmp_name'], $target.$pic1))
    {
      copy("C:/Program Files (x86)/EasyPHP-5.3.9/www/.../images/".$pic1, "C:/Program Files (x86)/EasyPHP-5.3.9/www/.../images/thumbs/".$pic1)
    }
    

    You should write the complete path "C:/..."

    0 讨论(0)
  • 2020-12-18 21:00

    It sounds like the second argument to move_uploaded_file should be a full file name instead of just the directory name. Also, probably only a style issue, but you should use consistent slashes in 'c:\wamp\www\uploads\images/'

    0 讨论(0)
  • 2020-12-18 21:00

    It will be like below in phalcon 3.42

    if ($this->request->hasFiles() == true) {
            // Print the real file names and sizes
            foreach ($this->request->getUploadedFiles() as $file) {
    
                //Print file details
                echo $file->getName(), " ", $file->getSize(), "\n";
    
                //Move the file into the application
                $file->moveTo($this->config->application->uploadsDir.$file->getName());
            }
        }
    
    0 讨论(0)
提交回复
热议问题