php - 为什么move_uploaded_file不允许我将它存储到我的驱动器?

the below demo of code is suppose to store my image into a directory, however, using xammp i am confused on if i need permission to store it there as i am getting warnings and the file is not saving where i would like it to go.

<?php
//simple image check using getimagesize() instead of extensions
if($_FILES)
{
    $empty_check = getimagesize($_FILES['file']['tmp_name']);
    if(empty($empty_check))
    {
        echo 'this is not an image';
    }
    else
    {
        echo 'you have uploaded ' . explode('.',$_FILES['file']['name'])[0].' and it is a ' . explode('.',$_FILES['file']['name'])[1].'.';
        //an example of how i would extract the extension
        $target = "C:\xampp\tmp";
        move_uploaded_file($_FILES['file']['tmp_name'], $target);
    }
}
?>

Escape the backslashes in your path!:

$target = "C:\xampp\tmp";
//should be
$target = "C:\\xampp\\tmp";

Considering \t is interpreted as a tab, your path reads like this:

$target = "C:[?]ampp    mp";

But really, you can just use the forward slashes:

$target = '/xampp/tmp';

If this still doesn't work, make sure you have write-rights on that directory, and fix that if necessary

Then, finally read the docs:

move_uploaded_file($_FILES['file']['tmp_name'], $target.'/filename_here.ext');

You have to add the file name to the target argument!

Try something like this

<?php 

//simple image check using getimagesize() instead of extensions

if($_FILES){
    $empty_check = getimagesize($_FILES['file']['tmp_name']);
    if(empty($empty_check)){
        echo 'this is not an image';
    }else{
        $exploded = explode('.',$_FILES['file']['name']);
        echo 'you have uploaded ' . current($exploded).' and it is a '.end($exploded);
        $target = 'C:\\xampp\\tmp\\'. $_FILES['file']['name'];
        move_uploaded_file($_FILES['file']['tmp_name'], $target);

    }

}
?>

You missed another slash I guess,

This code should work, Also use DIRECTORY_SEPARATOR instead of \

$target = 'C:\xampp\tmp\';
move_uploaded_file($_FILES['file']['tmp_name'], $target);

Right way to do it:

$target = $someDir . DIRECTORY_SEPARATOR.'xampp'.DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR;