unknown problem while uploading images in PHP












0















the code works, but it have some weird problem. I can't figure it out T.T anyone can help me?



If I upload 1 and 2 images, it works.
but if I upload 3 image, just first and last image it upload.



<?php
if (isset($_POST['upload'])) {
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$file = basename($_FILES["pictures"]["name"][$key]);
$FileType = strtolower(pathinfo($file,PATHINFO_EXTENSION));
$check = getimagesize($_FILES["pictures"]["tmp_name"][$key]);
if ($FileType != "jpg" && $FileType != "png" && $FileType != "jpeg") {
echo '<p class="error">Sorry only JPG, JPEG and PNG files are allowed</p>';
} elseif ($check == false) {
echo '<p class="error">File is not image</p>';
} else {
$newname = round(microtime(true));
$move = move_uploaded_file($_FILES["pictures"]["tmp_name"][$key], $newname.".".$FileType);
if (!$move) {
echo '<p class="error">Unable to upload image</p>';
} else {
echo '<p>upload success</p>';
}
}
}
}
}
?>

<form action="" method="post" enctype="multipart/form-data">
<p>Pictures:
<input type="file" name="pictures" />
<input type="file" name="pictures" />
<input type="file" name="pictures" />
<input type="submit" value="Send" name="upload" />
</p>
</form>


I'm sorry, I don't know how to explain it T.T










share|improve this question


















  • 3





    Check $newname, maybe it's the same for two files and one overwrites another.

    – u_mulder
    Nov 18 '18 at 18:29











  • How many times is <p>upload success</p> displayed?

    – Nigel Ren
    Nov 18 '18 at 18:31











  • it show 3 times <p>upload success</p>

    – shumaru
    Nov 18 '18 at 18:35











  • Think the @u_mulder comment is the reason - if you generate a file name you can check if it is already there using file_exists() and if so, generate a new name.

    – Nigel Ren
    Nov 18 '18 at 18:39













  • :D Thank you for help! It's overwrites another, I adding random number $newname = rand(100, 999).round(microtime(true)); and it works

    – shumaru
    Nov 18 '18 at 19:13
















0















the code works, but it have some weird problem. I can't figure it out T.T anyone can help me?



If I upload 1 and 2 images, it works.
but if I upload 3 image, just first and last image it upload.



<?php
if (isset($_POST['upload'])) {
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$file = basename($_FILES["pictures"]["name"][$key]);
$FileType = strtolower(pathinfo($file,PATHINFO_EXTENSION));
$check = getimagesize($_FILES["pictures"]["tmp_name"][$key]);
if ($FileType != "jpg" && $FileType != "png" && $FileType != "jpeg") {
echo '<p class="error">Sorry only JPG, JPEG and PNG files are allowed</p>';
} elseif ($check == false) {
echo '<p class="error">File is not image</p>';
} else {
$newname = round(microtime(true));
$move = move_uploaded_file($_FILES["pictures"]["tmp_name"][$key], $newname.".".$FileType);
if (!$move) {
echo '<p class="error">Unable to upload image</p>';
} else {
echo '<p>upload success</p>';
}
}
}
}
}
?>

<form action="" method="post" enctype="multipart/form-data">
<p>Pictures:
<input type="file" name="pictures" />
<input type="file" name="pictures" />
<input type="file" name="pictures" />
<input type="submit" value="Send" name="upload" />
</p>
</form>


I'm sorry, I don't know how to explain it T.T










share|improve this question


















  • 3





    Check $newname, maybe it's the same for two files and one overwrites another.

    – u_mulder
    Nov 18 '18 at 18:29











  • How many times is <p>upload success</p> displayed?

    – Nigel Ren
    Nov 18 '18 at 18:31











  • it show 3 times <p>upload success</p>

    – shumaru
    Nov 18 '18 at 18:35











  • Think the @u_mulder comment is the reason - if you generate a file name you can check if it is already there using file_exists() and if so, generate a new name.

    – Nigel Ren
    Nov 18 '18 at 18:39













  • :D Thank you for help! It's overwrites another, I adding random number $newname = rand(100, 999).round(microtime(true)); and it works

    – shumaru
    Nov 18 '18 at 19:13














0












0








0








the code works, but it have some weird problem. I can't figure it out T.T anyone can help me?



If I upload 1 and 2 images, it works.
but if I upload 3 image, just first and last image it upload.



<?php
if (isset($_POST['upload'])) {
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$file = basename($_FILES["pictures"]["name"][$key]);
$FileType = strtolower(pathinfo($file,PATHINFO_EXTENSION));
$check = getimagesize($_FILES["pictures"]["tmp_name"][$key]);
if ($FileType != "jpg" && $FileType != "png" && $FileType != "jpeg") {
echo '<p class="error">Sorry only JPG, JPEG and PNG files are allowed</p>';
} elseif ($check == false) {
echo '<p class="error">File is not image</p>';
} else {
$newname = round(microtime(true));
$move = move_uploaded_file($_FILES["pictures"]["tmp_name"][$key], $newname.".".$FileType);
if (!$move) {
echo '<p class="error">Unable to upload image</p>';
} else {
echo '<p>upload success</p>';
}
}
}
}
}
?>

<form action="" method="post" enctype="multipart/form-data">
<p>Pictures:
<input type="file" name="pictures" />
<input type="file" name="pictures" />
<input type="file" name="pictures" />
<input type="submit" value="Send" name="upload" />
</p>
</form>


I'm sorry, I don't know how to explain it T.T










share|improve this question














the code works, but it have some weird problem. I can't figure it out T.T anyone can help me?



If I upload 1 and 2 images, it works.
but if I upload 3 image, just first and last image it upload.



<?php
if (isset($_POST['upload'])) {
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$file = basename($_FILES["pictures"]["name"][$key]);
$FileType = strtolower(pathinfo($file,PATHINFO_EXTENSION));
$check = getimagesize($_FILES["pictures"]["tmp_name"][$key]);
if ($FileType != "jpg" && $FileType != "png" && $FileType != "jpeg") {
echo '<p class="error">Sorry only JPG, JPEG and PNG files are allowed</p>';
} elseif ($check == false) {
echo '<p class="error">File is not image</p>';
} else {
$newname = round(microtime(true));
$move = move_uploaded_file($_FILES["pictures"]["tmp_name"][$key], $newname.".".$FileType);
if (!$move) {
echo '<p class="error">Unable to upload image</p>';
} else {
echo '<p>upload success</p>';
}
}
}
}
}
?>

<form action="" method="post" enctype="multipart/form-data">
<p>Pictures:
<input type="file" name="pictures" />
<input type="file" name="pictures" />
<input type="file" name="pictures" />
<input type="submit" value="Send" name="upload" />
</p>
</form>


I'm sorry, I don't know how to explain it T.T







php image-uploading






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 18 '18 at 18:21









shumarushumaru

32




32








  • 3





    Check $newname, maybe it's the same for two files and one overwrites another.

    – u_mulder
    Nov 18 '18 at 18:29











  • How many times is <p>upload success</p> displayed?

    – Nigel Ren
    Nov 18 '18 at 18:31











  • it show 3 times <p>upload success</p>

    – shumaru
    Nov 18 '18 at 18:35











  • Think the @u_mulder comment is the reason - if you generate a file name you can check if it is already there using file_exists() and if so, generate a new name.

    – Nigel Ren
    Nov 18 '18 at 18:39













  • :D Thank you for help! It's overwrites another, I adding random number $newname = rand(100, 999).round(microtime(true)); and it works

    – shumaru
    Nov 18 '18 at 19:13














  • 3





    Check $newname, maybe it's the same for two files and one overwrites another.

    – u_mulder
    Nov 18 '18 at 18:29











  • How many times is <p>upload success</p> displayed?

    – Nigel Ren
    Nov 18 '18 at 18:31











  • it show 3 times <p>upload success</p>

    – shumaru
    Nov 18 '18 at 18:35











  • Think the @u_mulder comment is the reason - if you generate a file name you can check if it is already there using file_exists() and if so, generate a new name.

    – Nigel Ren
    Nov 18 '18 at 18:39













  • :D Thank you for help! It's overwrites another, I adding random number $newname = rand(100, 999).round(microtime(true)); and it works

    – shumaru
    Nov 18 '18 at 19:13








3




3





Check $newname, maybe it's the same for two files and one overwrites another.

– u_mulder
Nov 18 '18 at 18:29





Check $newname, maybe it's the same for two files and one overwrites another.

– u_mulder
Nov 18 '18 at 18:29













How many times is <p>upload success</p> displayed?

– Nigel Ren
Nov 18 '18 at 18:31





How many times is <p>upload success</p> displayed?

– Nigel Ren
Nov 18 '18 at 18:31













it show 3 times <p>upload success</p>

– shumaru
Nov 18 '18 at 18:35





it show 3 times <p>upload success</p>

– shumaru
Nov 18 '18 at 18:35













Think the @u_mulder comment is the reason - if you generate a file name you can check if it is already there using file_exists() and if so, generate a new name.

– Nigel Ren
Nov 18 '18 at 18:39







Think the @u_mulder comment is the reason - if you generate a file name you can check if it is already there using file_exists() and if so, generate a new name.

– Nigel Ren
Nov 18 '18 at 18:39















:D Thank you for help! It's overwrites another, I adding random number $newname = rand(100, 999).round(microtime(true)); and it works

– shumaru
Nov 18 '18 at 19:13





:D Thank you for help! It's overwrites another, I adding random number $newname = rand(100, 999).round(microtime(true)); and it works

– shumaru
Nov 18 '18 at 19:13












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364106%2funknown-problem-while-uploading-images-in-php%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364106%2funknown-problem-while-uploading-images-in-php%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)