簡體   English   中英

無法從php檢索變量

[英]Can't retrieve variable from php

PHP文件:

<?php

#Communication with the API
require_once 'api.php';
$cloudkey = new CloudKey($user_id, $api_key);


if(isset($_FILES["FileInput"]) && $_FILES["FileInput"]["error"]== UPLOAD_ERR_OK)
{
    //Deleted Code: putting the uploaded files in my server.

    if(move_uploaded_file($_FILES['FileInput']['tmp_name'], $UploadDirectory.$NewFileName ))
       {

 $video_file = "/home/george/public_html/q/"; 
 $video_file = $video_file . $NewFileName; 

#Sending the video from my server to the cloud server
$res = $cloudkey->file->upload_file($video_file);

#The cloud server will create a link
$source_url = $res->url;

#The cloud server will convert the video very fastly
while(1) {
    #Deleted Code: Conversion
    if ($asset->status == 'ready') {
        # A lot of code. It will convert the videos here and if it succeeds it will stop.
    break;
    # If the conversion fails, display error
    } else if ($asset->status == 'error') {
        echo "Error while transcoding the media\n";
    }
    sleep(1);
}


# Getting the URL of a thumbnail
echo $thumb = $cloudkey->media->get_stream_url(array('id' => $media_id, 'asset_name' => 'jpeg_thumbnail_source'));

    }else{
        die('error uploading File!');
    }

}
else
{
    die('Something went wrong!');
}
?>

HTML檔案:

  {literal}
<script type="text/javascript">


$(document).ready(function() { 
    var options = { 
            target:   '#output',   // target element(s) to be updated with server response 
            beforeSubmit:  beforeSubmit,  // pre-submit callback 
            success:       afterSuccess,  // post-submit callback 
            uploadProgress: OnProgress, //upload progress callback 
            resetForm: true        // reset the form after successful submit 
        }; 


//function after succesful file upload (when server response)
function afterSuccess()
{
    $('#loading-img').hide(); //hide submit button
    $('#progressbox').fadeOut(); //hide progress bar
    //I WANT TO INSERT SOMETHING HERE.
}



//progress bar function
function OnProgress(event, position, total, percentComplete)
{
   //DOES NOT INTEREST YOU
}); 

</script>


{/literal} 

<div id="output"></div>

我正在使用smarty模板引擎。 我有一個html上載表格,該表格將與php文件progressupload.php進行通信,其中php文件將轉換視頻(使用API​​服務)並在完成時返回響應。

當用戶上傳視頻文件時,ajax將接管顯示的百分比(以html格式),並將文件發送到progressupload.php ,當progressupload.php完成轉換后,只需將回顯的所有內容輸出到php中這在html文件中(我不知道為什么): <div id="output"></div>

我想要的是:

progressupload.php完成轉換后,它將生成一個縮略圖(屏幕快照)並將其鏈接存儲在$thumb 我想檢索$thumb並將其顯示給用戶使用jquery。

現在,如果您查看HTML代碼,則afterSuccess()是我要向用戶顯示縮略圖的函數:

function afterSuccess()
{
    $('#loading-img').hide(); //hide submit button
    $('#progressbox').fadeOut(); //hide progress bar
    //I WANT TO SHOW THE THUMBNAIL HERE.
}

我刪除了很多不必要的代碼,這些代碼可能會使您分心。 請記住,我使用的是smarty模板引擎,我的html文件未以.php結尾 ,我無法直接回顯該變量。 創建變量后,如何檢索php變量並將其放入jquery方法中。

我懷疑如果直接在頁面加載時檢索變量,由於鏈接需要創建時間(上載,轉換),因此它不會成功獲取$thumb 如何檢索該$thumb

假設您正在使用jQuery.ajax();
$ .ajax“成功”回調中的第一個參數是從服務器端返回的參數。

function afterSuccess( response /** this is what returned from your server **/ )
{
    $('#loading-img').hide(); //hide submit button
    $('#progressbox').fadeOut(); //hide progress bar
    //I WANT TO INSERT SOMETHING HERE.

    console.log(response); // here you can access your $thumbnail
    // below code is untested but it should work
    // $("#output").html("<img src='"+response+"' class='thumbnail' />");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM