2014-08-11 07:01
浏览 115


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++) 

    $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

    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]

    打赏 评论
  • dongshuo6185 2014-08-11 07:09

    I feel you should add


    in image destination path

    打赏 评论

相关推荐 更多相似问题