move_uploaded_file() error on windows with

2019-02-21 09:11发布

问题:

Warning: move_uploaded_file(C:\wamp\www/uploads/a.mp3): failed to open stream: No such file or directory in C:\wamp\www\display\uploadfile.php on line 206

Warning: move_uploaded_file(): Unable to move 'C:\wamp\tmp\php75FD.tmp' to 'C:\wamp\www/uploads/a.mp3' in C:\wamp\www\display\uploadfile.php on line 206

var_dump:

array (size=1)
  'file' => 
    array (size=5)
      'name' => string 'a.mp3' (length=5)
      'type' => string 'audio/mp3' (length=9)
      'tmp_name' => string 'C:\wamp\tmp\php75FD.tmp' (length=23)
      'error' => int 0
      'size' => int 4030592

tmp and upload directories have permissions set to everyone > Full Permissions

PHP has upload filesize set correctly

I have no idea why the file wont upload...

Edit: Code: http://pastebin.com/kFG2v2PJ

回答1:

Problem: C:\wamp\www/uploads/.

Change your slashes to backslashes and make sure the directory C:\wamp\www\uploads\ exists. You could use the DIRECTORY_SEPARATOR constant to make your code work on multiple systems.

Also, without seeing your code, you need to make sure you're putting the correct paramaters in move_uploaded_file()

Edit after code:

Change

$target_path = APP_PATH."/uploads/";

to

$target_path = APP_PATH . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR;


回答2:

is your /uploads directory exists? if yes then check var_dump($_FILES) check if $_FILES['uploaded']['error']. contains 0, which means "no error"