doutui7955 2017-03-09 13:55
浏览 26

如何使用javascript和php获取加载图像的URL - 解析PHP SDK

I'm very new to php and javascript, I'm trying to make a form where you can upload an image and display its preview on the same page, and my code works, the problem is that I need to get that image's URL in order to upload it to my Parse Server. Here's the code I use:

<!-- UPLOAD AVATAR -->
<div class="text-center">
<img id="avatar-img" src="images/80.png" width="100" height="100" class="img-circle img-thumbnail img-responsive"></p>
<input style="display:none" id="input-image-hidden" onchange="document.getElementById('avatar-img').src = window.URL.createObjectURL(this.files[0])" type="file" accept="image/jpeg, image/png">
<button class="btn btn-primary btn-block" onclick="HandleBrowseClick('input-image-hidden');" >Upload an avatar</button>

<p id="theImageURL"></p>

<script type="text/javascript">
getImageURL();

     function HandleBrowseClick(input_image) {
       var fileinput = document.getElementById(input_image);
       fileinput.click();
     }

     function getImageURL() {
         var x = document.getElementById("avatar-img").src;
         document.getElementById("theImageURL").innerHTML = x;
     }

 </script>

So, when i first run my signUp.php page, I can get the URL of my 80.png image, which looks like: http://www.example.com/images/80.png and it get shown into my <p id="theImageURL"></p> tag. I need to get that string and pass it to a php function to upload that image to Parse Server:

    $localFilePath = "URL_OF_MY_PREVIEW_IMAGE";
    $file = ParseFile::createFromFile($localFilePath, "image.jpg");

Any help will be greatly appreciated.

Thanks!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度