PHP给出错误,不会移动文件

时间:2013-11-08 07:37:00

标签: php file-upload

我此时设置了一个上传页面,允许用户一次上传一张图片,并尝试更改以允许使用标签上传多张图片。当我进入并对表格进行更改时,它告诉我第19行和第43行有错误不是参数。 (错误#1)strtolower()期望参数1为字符串,在第19行的C:\ wamp \ www \ webstuffs \ upload.php中给出数组。(错误#2)move_uploaded_file()期望参数1为字符串,数组在第43行的C:\ wamp \ www \ webstuffs \ upload.php中给出。

<?php
if(isset($_FILES['file']))
{

$file = $_FILES ['file'];
$name = $file ['name'];
$type = $file ['type'];
$size = $file ['size'];
$tmppath = $file ['tmp_name']; 


                        function create_slug($slug, $hyphenate = true)
                            {
                            19. $slug = strtolower($slug);
                                if($hyphenate)
                                    {
                                $slug = preg_replace("/[-\s\W]/","-",$slug);
                                    }
                                 return preg_replace("/[^a-z0-9-]/", "",strtolower($slug));
                            }
                        $name=create_slug($name);






    $res=$ob->upload();
    $user=$_SESSION['user'];
    $tmp=0;

while($row=mysql_fetch_array($res))
    {
        $tag=$row['sno'];

        if(isset($_POST[$tag]))
            {
            43. move_uploaded_file ($tmppath, 'images/gallery/'.$name.'.jpg');
                mysql_query("insert into gallery(image,tag,user) values('".$name."','".$tag."','".$user."')");
                $tmp=1;
            }
    }   










}
?>

这是表格

<form name="f3" action="upload.php" method="post" enctype="multipart/form-data";>
            <div style="clear:both;margin-left:50px;height:40px; ">
                <div style="float:left;width:150px;font-size:25px;font-family:'Monotype Corsiva'; color:#fc6464;font-weight:bold;margin-top:-8px;">Choose Image</div>
                <div style="float:left;width:40px;color:#CCCCCC; ">:</div>
                <div style="float:left;width:200px; "><input type="file" name="file[]" multiple id="file" style="width:180px; "></div>
            </div>




                <div class="multiselect">

                <?php

                $res=$ob->alltags();
                    while($row=mysql_fetch_array($res))
                        {
                            $tags=$row['tags'];
                            $sno=$row['sno'];
                            echo"<label><input type='checkbox' name='".$sno."' value='".$sno."' />$tags</label>";
                        }
                    ?>

        </div>

        <br/>

        <div style="clear:both;margin-left:50px;height:40px; ">
                <div style="width:120px;font-size:25px;font-family:'Monotype Corsiva'; color:#fc6464;font-weight:bold;margin-top:-8px;">Select Tags</div>

                <div style="clear:both;margin-left:0px;height:40px; ">
                <a href="javascript:void();" onClick="blank3();"><img src="images/submit.png"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void();" onClick="blank1();"><img src="images/reset.png"></a>
            </div>

            </div>

            </form>

我看了一切,我不知道我需要做些什么来解决这个问题

1 个答案:

答案 0 :(得分:0)

  1. $slug是使用preg_replace后的数组。

  2. $_FILES['file']也是一个数组,因为您在输入名称中使用了files[]

  3. 因此,你必须遍历两个数组,然后它们将在函数的变量中用作字符串。

    所以$tmppath = $file['tmp_name'];应该在循环中,例如:$tmppath = $file[$i]['tmp_name'];