dongxin1980 2014-08-11 07:01
浏览 118
已采纳

无法使用move_uploaded_file上传多个图像

I have a form, upon submission, it will create a new directory, all images submitted along with the form will be upload in the said directory.

this is the shortened code.

    mkdir('uploads/'.$name, 0777, true); //create directory

    $count = count($_FILES['images']['tmp_name']); //count all uploaded files
    for ($i=0; $i<$count; $i++) 
    { 

    //formatting
    $file     = $_FILES['images']['name'][$i];
    $filename = strtolower($file);
    $random   = rand(0, 999); //Random number to be added to name.
    $newfile  = $random.$filename; //new file name


    //upload
    if (move_uploaded_file($newfile, "uploads/".$name."/".$newfile)) 
    {
     echo "uploaded";
    } else {
     echo " failed";
    }

    }

if i echo the directory echo "upload to =" . $teamdir."/".$newfile;

it shows the correct path /uploads/john/567banner_0.jpg

but the image aren't being uploaded.

  • 写回答

2条回答 默认 最新

  • douzuanze0486 2014-08-11 07:09
    关注
    bool move_uploaded_file ( string $filename , string $destination )
    

    Your first parameter has to be the source so you have to give it the temp name assigned by php.

    In your case : $_FILES['images']['tmp_name'][$i]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程