成功上传后如何从PHP到JavaScript或Ajax发送多个URL

PHP用于上传图像,带有用于图像调整大小和校正方向的代码:

<?php
$result = 0;
define('FORUM_PATH', '/home/***/***/');
require_once(FORUM_PATH . '***/api/member/api_member_login.php');
$ipbMemberLoginApi = new apiMemberLogin();
$ipbMemberLoginApi->init();
$member        = $ipbMemberLoginApi->getMember();
$id            = ($member['member_id']);
$upload_folder = "uploads/$id/" . date("Y_m_d");
if (!is_dir($upload_folder)) mkdir($upload_folder, 0755, true);
$countfiles = count($_FILES['myfile']['name']);
for ($i = 0; $i < $countfiles; $i++) {
    if (is_uploaded_file($_FILES['myfile']['tmp_name'][$i]) && ($_FILES["myfile"]["size"][$i] <= 28192 * 1 * 28192)) {
        $enabled = array(IMAGETYPE_PNG,IMAGETYPE_JPEG,IMAGETYPE_PNG,IMAGETYPE_GIF);
        list($width, $height, $extension) = getimagesize($_FILES['myfile']['tmp_name'][$i]);
        if (in_array($extension, $enabled)) {
            $ext     = "." . strtolower(pathinfo($_FILES['myfile']["name"][$i], PATHINFO_EXTENSION));
            $imglink = $upload_folder . '/' . 'MCG_' . $id . '_' . uniqid() . $ext;
            if (@move_uploaded_file($_FILES['myfile']['tmp_name'][$i], $imglink))
            $max_width  = 1024;
            $max_height = 800;
            $im         = new Imagick();
            $im->readImage($imglink);
            $exif = exif_read_data($im);
            if (!empty($exif['Orientation'])) {
                switch ($exif['Orientation']) {
                    case 8:
                        $im = imagerotate($im, 90, 0);
                        break;
                    case 3:
                        $im = imagerotate($im, 180, 0);
                        break;
                    case 6:
                        $im = imagerotate($im, -90, 0);
                        break;
                }
            }
            $im->stripImage();
            $im->resizeImage(min($im->getImageWidth(), $max_width), min($im->getImageHeight(), $max_height), imagick::FILTER_CATROM, 1, true);
            file_put_contents($imglink, $im);
            $finalLink = '\n[img]https://***.com/***/' . $imglink . '[/img]\n';
            $result    = 1;
        } else {
            $result = 0;
        }
    }
}
?>
<script language="javascript" type="text/javascript">window.top.window.stopUpload(<?=$result; ?>,'<?=$finalLink;?>');</script>

JS代码,用于接收并将$ finalLink插入ID为fast-reply_textarea的编辑器中

function startUpload() {
    document.getElementById("myf1_upload_process").style.visibility = "visible";
    document.getElementById("imageUpload").style.visibility = "hidden";
    return true;
}

function stopUpload(result, finalLink) {
    if (result == 1) {
        error = "";
        topic = document.getElementById("fast-reply_textarea");
        topic.focus();
        topic.value += finalLink;
    } else {
        error = '<span class="myemsg">***</span>';
    }
    document.getElementById("myf1_upload_process").style.visibility = "hidden";
    document.getElementById("myf1_upload_form").innerHTML = error + '<input id="file_browse" onchange="this.form.submit()" type="file" name="myfile[]" multiple accept="image/*" size="0" /><input type="submit" name="submitBtn" class="mysbtn" value="Upload Image" />';
    document.getElementById("imageUpload").style.visibility = "visible";
    return true;
}

如果在上面的PHP中添加代码$ result = 1 ;:

echo "<script>console.log('$finalLink');</script>";

我看到所有链接,例如:

[img]https://***.com/***/uploads/24/2020_05_08/MCG_24_64sd6f5165gsd.png[/img]
[img]https://***.com/***/uploads/24/2020_05_08/MCG_24_5eb54fdg4f5hd.jpg[/img]
[img]https://***.com/***/uploads/24/2020_05_08/MCG_24_496s4gs6d5g65.png[/img]
[img]https://***.com/***/uploads/24/2020_05_08/MCG_24_984dfg6s4dg4d.jpg[/img]

需要将此链接发送到JS并将链接插入ID为fast-reply_textarea的编辑器中,但如何处理?