dongmei5168 2013-06-06 23:28
浏览 16
已采纳

php文件上传未定义的偏移通知[重复]

This question already has an answer here:

I have a bit of cod the works fine on MAMP but gives me an error on WAMP. The code is:

$uploads = ""; 
for($x=0; $x<$count_data; $x++)
{
    $uploads .= $_FILES['file']['name'][$x] . ' ';
}

And the error is:

Notice: Undefined offset: 1

Notice: Undefined offset: 2

Notice: Undefined offset: 3

Notice: Undefined offset: 4

Any ideas?

Here is the file up load code:

$number_of_file_fields = 0;
$number_of_uploaded_files = 0;
$number_of_moved_files = 0;
$uploaded_files = array();
$upload_directory = dirname(__file__) . '/../uploads/'; //set upload directory
$count_data=count($_FILES['file']) ;
$uploads = ""; 
for($x=0; $x<$count_data; $x++)
{
    $uploads .= $_FILES['file']['name'][$x] . ' ';
}



for ($i = 0; $i < count($_FILES['file']['name']); $i++) {
    $number_of_file_fields++;
    if ($_FILES['file']['name'][$i] != '') { //check if file field empty or not
        $number_of_uploaded_files++;
        $uploaded_files[] = $_FILES['file']['name'][$i];
        if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $upload_directory . $orderNumber . "_" . $_FILES['file']['name'][$i])) {
            $number_of_moved_files++;
        }
    }
}
</div>
  • 写回答

1条回答 默认 最新

  • drfu80954 2013-06-06 23:41
    关注

    There's 2 ways for multiple file uploads to be organized in the $_FILES array, depending on whether they have the same name attribute or not.

    To handle both cases, try something like this:

    $uploads = '';
    foreach ($_FILES as $inputName => $fileInfo) {
        foreach ((array) $fileInfo['name'] as $n) {
            $uploads .= $n . ' ';
        }
    }
    

    To help debug the different between the two hosts, try echo'ing out the contents of the $_FILES array on each and see how it's different.

    print_r($_FILES);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题