2014-11-19 20:41 阅读 16


I am having a small issue that would love to get some assistance on, I have a image upload that I am building and would like to move the file to a folder image and copy it to a folder image_thumb also. I am using arrays with keys but when I try to add the copy() function it gives an error saying that it failed to open stream.

It manages to upload the image to image folder, but not the other one, could someone tell me what I did wrong in the copy($key, "image_thumbnail/" . $_FILES['images']['name'][$i]); function.

Thank you for the awesome upcoming assistance :)

Here is my code

if (isset($_POST['addpart'])) {

    $image = $_FILES['images']['tmp_name'];
    $i     = 0;
    foreach ($image as $key) {
        move_uploaded_file($key, "image/" . $_FILES['images']['name'][$i]);
        copy($key, "image_thumbnail/" . $_FILES['images']['name'][$i]);
    echo 'Uploaded';
    echo '<hr>';

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    dongmangji0950 dongmangji0950 2014-11-19 20:53

    When you do move_uploaded file it is removing tmp file from $_FILES['images']['tmp_name'].

    You have to make copy like this:

    move_uploaded_file($key, "image/" . $_FILES['images']['name'][$i]);
    copy($_FILES['images']['name'][$i], "image_thumbnail/" . $_FILES['images']['name'][$i]);
    点赞 评论 复制链接分享
  • duankeng2026 duankeng2026 2014-11-19 20:48

    Instead of

    copy($key, "image_thumbnail/" . $_FILES['images']['name'][$i]);

    use this

    copy("image/" . $_FILES['images']['name'][$i], "image_thumbnail/" . $_FILES['images']['name'][$i]);
    点赞 评论 复制链接分享