我想合并此上载图片ajax url重定向并在同一功能中运行

 ***

我想合并此代码最后给出的ajax重定向,即“ upload.php” 用于将我的图片上传到我的文件管理器,此代码工作正常,我可以上传 图像到我的文件管理器,并将其地址复制到我的剪贴板,但我想摆脱 我尝试了saveral方法的upload.php文件,但是它们没有用,所以任何人都可以帮助我

更新此...。

    `<!DOCTYPE html>
    <html>
     <head>
      <title> Upload File </title>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
     </head>
     <body>
      <br />

     <img src="/a.png" onclick="document.getElementById('file').click()" width="45" height="41" /> 

      <input type='file' name="file" id="file" style="display:none">

       <br />


       <span id="uploaded_image"></span>  
     </body>
    </html>

    <script>
    $(document).ready(function(){
     $(document).on('change', '#file', function(){
      var name = document.getElementById("file").files[0].name;
      var form_data = new FormData();
      var ext = name.split('.').pop().toLowerCase();
      if(jQuery.inArray(ext, ['gif','png','jpg','tiff','psd','ai','raw','jpeg']) == -1) 
      {
       alert("Invalid Image File");
      }
      var oFReader = new FileReader();
      oFReader.readAsDataURL(document.getElementById("file").files[0]);
      var f = document.getElementById("file").files[0];
      var fsize = f.size||f.fileSize;
      if(fsize > 500000000000000000000000000)
      {
       alert("Image File Size is very big");
      }
      else
      {
       form_data.append("file", document.getElementById('file').files[0]);
       $.ajax({
        url:"upload.php",
        method:"POST",
        data: form_data,
        contentType: false,
        cache: false,
        processData: false,
        beforeSend:function(){
         $('#uploaded_image').html("<label class='text-success'>Image Uploading...</label>");
        },   
        success:function(data)
        {
         $('#uploaded_image').html(data);
        }
       });
      }
     });
    });
    </script>`




    ------------------------------------------------------
      you can see  upload.php here

上传.php文件

    `<?php
        //upload.php
        if($_FILES["file"]["name"] != '')
        {
            $test = explode('.', $_FILES["file"]["name"]);
            $ext = end($test);
            $name = rand(100, 99999999999) . '.' . $ext;
            $location = './upload/' . $name; 
            $url= 'http://xyz..com/love/upload/' . $name;

            move_uploaded_file($_FILES["file"]["tmp_name"], $location);
             echo '<img src="'.$location.'" height="150" width="225" class="img-thumbnail" />';

             echo "\n\n\n\n$url";
        } else {
            $url = "";
        }
    ?>

    <!DOCTYPE html>
    <html>
    <head>
        <title>Copy Paste This IMG LINK </title>
        <style>
    .button {

      background-color: #4CAF50;
      border: none;
      color: white;
      padding: 5px 1px;
      text-align: center;
      text-decoration: none;
      display: inline-block;
      font-size: 11px;
      margin: 2px 1px;
      cursor: pointer;
    }

    </style>

    <script src="sounds.js?xyz=<?php print $settings['forcereload'];?>"></script>
    <script src="blabax.js?xyz=<?php print $settings['forcereload'];?>"></script>


    </head>

    <body>



    ?>

        <input   type="text" value="<?php echo $url; ?>" id="text_inpu" readonly>


        <button onclick="myFunction()"><h4 style="color:green;font-size:12px;"><b>Click Here & Copy Paste Img Link</b></h4></button>

        <script>
        function myFunction() {
            let inputEl = document.getElementById("text_inpu");
            inputEl.select();                                    // Select element
            inputEl.setSelectionRange(0, inputEl.value.length); // select from 0 to element length

            const successful = document.execCommand('copy');   // copy input value, and store success if needed

            if(successful) {

                 alert("Copied the text: " + inputEl.value);
            } else {
                 ...
            }
        }
        </script>

    </body>
    </html> `
评论