0

我从我的应用程序获取图像到这个 php 代码:

<?php 

$target = "upload/"; 
$name="checks";
$target = $target . basename( $_FILES['uploaded'].$name); 

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
{
echo "yes";
} 
else {
echo "no";
}
?> 

问题是我上传的图片的每个名称都以“Array”开头。

例如,$name现在是“checks”,所以文件名是“Arraychecks”。

为什么会这样?

谢谢您的帮助。

4

3 回答 3

1
$name = $_FILES['checks']['name'];
$fileElementName = 'checks';
$path = 'upload/'; 
$location = $path . $_FILES['checks']['name']; 
move_uploaded_file($_FILES['checks']['tmp_name'], $location); 

现在在您的插入查询中使用 $name

于 2013-08-29T09:31:56.787 回答
1

$_FILES['uploaded']是一个数组。

Array
(
    [name] => Array
        (
            [1] => Array
                (
                    [0] => 
                )

        )

    [type] => Array
        (
            [1] => Array
                (
                    [0] => 
                )

        )

    [tmp_name] => Array
        (
            [1] => Array
                (
                    [0] => 
                )

        )

    [error] => Array
        (
            [1] => Array
                (
                    [0] => 4
                )

        )

    [size] => Array
        (
            [1] => Array
                (
                    [0] => 0
                )

        )

)

您可能正在寻找$_FILES['uploaded']['name']

于 2013-08-29T09:28:46.853 回答
1

获取单词Array是将数组转换为字符串的典型症状:

$data = array(10, 20, 30);
var_dump( (string)$data );
// Notice: Array to string conversion
// string(5) "Array"

从您的代码中可以明显看出这$_FILES['uploaded']是一个数组,因为您这样做:

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 

...所以这是不对的:

$target = $target . basename( $_FILES['uploaded'].$name); 

也许你有这个想法:

$target = $target . basename( $_FILES['uploaded']['name'].$name); 
于 2013-08-29T09:35:09.347 回答