Rewind arrays before foreach loops over all the elements.

(fixed a small typo as well)
This commit is contained in:
green-ponies (jgen)
2012-02-04 15:35:21 -05:00
parent cd1f5d9ed0
commit 3b028696a0
7 changed files with 23 additions and 2 deletions

View File

@@ -152,12 +152,14 @@ class Upload extends SimpleExtension {
$tags = ''; // Tags aren't changed when uploading. Set to null to stop PHP warnings.
if(count($_FILES)) {
reset($_FILES); // rewind to first element in array.
foreach($_FILES as $file) {
$ok = $this->try_upload($file, $tags, $source, $image_id);
break; // leave the foreach loop.
}
}
else {
reset($_POST); // rewind to first element in array.
foreach($_POST as $name => $value) {
if(substr($name, 0, 3) == "url" && strlen($value) > 0) {
$ok = $this->try_transload($value, $tags, $source, $image_id);
@@ -188,9 +190,11 @@ class Upload extends SimpleExtension {
$source = isset($_POST['source']) ? $_POST['source'] : null;
$ok = true;
foreach($_FILES as $file) {
reset($_FILES); // rewind to first element in array.
$ok = $ok & $this->try_upload($file, $tags, $source);
}
foreach($_POST as $name => $value) {
reset($_POST); // rewind to first element in array.
if(substr($name, 0, 3) == "url" && strlen($value) > 0) {
$ok = $ok & $this->try_transload($value, $tags, $source);
}