move_uploaded_file() wordpress plugin

2019-06-08 04:47发布

问题:

I'm creating a wordpress plugin and trying to create an upload function. However, I'm getting these errors:

Warning: move_uploaded_file(logos/5041796eeedf21346468206.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/wordpress/wp-content/plugins/logo-updating/logo_menu.php on line 15

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/Applications/XAMPP/xamppfiles/temp/phpeIJRwj' to 'logos/5041796eeedf21346468206.jpg' in /Applications/XAMPP/xamppfiles/htdocs/wordpress/wp-content/plugins/logo-updating/logo_menu.php on line 15

My code for uploading:

$tmp = $_FILES['logoUpload']['tmp_name'];

$extension = explode(".", $_FILES['logoUpload']['name']);
$everything = count($extension);

$ext = $extension[$everything - 1];

$newName = uniqid().time().".".$ext;
$newName2 = uniqid().time()."_banner.".$ext;

move_uploaded_file($tmp, "logos/".$newName);

$fullLink = "logos/".$newName;

回答1:

$path_array  = wp_upload_dir();
    $path = str_replace('\\', '/', $path_array['path']);




        $target_path_sia = uniqid().$_FILES["file"]["name"];
      move_uploaded_file($_FILES["file"]["tmp_name"],$path. "/" . $target_path_sia);
      echo "Stored in: " . $path. "/"  .$target_path_sia;