本文介绍了如何使用html文件选择器(输入类型=“文件”)将照片上传到Facebook(图形api)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个html文件,从用户的computer.code中选择图像。

I have a html file which select images from user's computer.code is given bellow

  <html>
    <body>
    <form enctype="multipart/form-data" action="http://localhost/uploader/upload.php" method="POST">
    Please choose a photo:
    <input name="source" type="file"><br/><br/>
    Say something about this photo:
    <input name="message" type="text" value=""><br/><br/>
    <input type="submit" value="Upload"/><br/>
    </form>
    </body>
 </html>

当我按上传按钮时,我需要将所选图像的真实路径传递到upload.php upload.php的file.code在下面给出

When I press upload button,I need to pass the real path of the selected image into upload.php file.code of the upload.php is given bellow

<?php
    include_once 'fbmain.php';
    //some codes
    try{
    $uid = $facebook->getUser();
        $me = $facebook->api('/me');
        $token = $session['access_token'];//here I get the token from the $session array
        $album_id = '2179901265385';//MY ALBUM ID

        //upload my photo
        $FILE_PATH= 'HERE_I_NEED_THE_REAL_PATH_OF_THE_IMAGE';
        $facebook->setFileUploadSupport(true);
        $args = array('message' => 'Photo Caption');
        $args['image'] = '@' . realpath($FILE_PATH);

        $data = $facebook->api('/'. $album_id . '/photos?access_token='. $token, 'post', $args);

    } catch(FacebookApiException $e){
        echo "Error:" .$e;
    }
?>

当我给出一个变量 $ FILE_PATH的路径(例如:$ FILE_PATH = 'C:\My Documents\My Pictures\a.jpg')它工作正常。但是我需要从html文件选择器中取这个路径。

是有一种方法来做这个吗?

至少有人可以告诉我一种方法来访问文件选择器的文本字段的值?($ _ POST ['texboxname'] 不在这里工作)。

我可以找到许多教程,使用图形API将图像上传到Facebook,但没有使用html文件选择器

任何人都可以帮我吗?

When I give a path to variable $FILE_PATH (eg: $FILE_PATH = 'C:\My Documents\My Pictures\a.jpg') it works fine.But I need to take this path from html file selector.
Is there a way to do this?
At least can anyone tell me a way to access the value of the text field of file selector?($_POST['texboxname'] doesn't work here).
I could find many tutorials which upload images into facebook using graph api but nothing with html file selector.
So can anyone please help me?

推荐答案

尝试这个:只有一个例子

Try This: Only an example

<html>
    <body>
    <form enctype="multipart/form-data" action="upload.php" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    Please choose a photo:
    <input name="photo" type="file"><br/><br/>
    Say something about this photo:
    <input name="message" type="text" value=""><br/><br/>
    <input type="submit" value="Upload"/><br/>
    </form>
    </body>
 </html>


<?php
//upload.php
if(isset($_FILES['photo']) && isset($_POST['message'])){

    $uploadfile = './uploads/'.basename($_FILES['photo']['name']);

    $iStats=getimagesize($_FILES['photo']['tmp_name']);

    if (isset($iStats['mime']) && $iStats[0]>0) {
        move_uploaded_file($_FILES['photo']['tmp_name'], $uploadfile);
        include_once 'fbmain.php';
        try{
            $uid = $facebook->getUser();
            $me = $facebook->api('/me');
            $token = $session['access_token'];//here I get the token from the $session array
            $album_id = '2179901265385';//MY ALBUM ID
            $facebook->setFileUploadSupport(true);
            $args = array('message' => $_POST['message']);
            $args['image'] = '@' . realpath($uploadfile);

            $data = $facebook->api('/'. $album_id . '/photos?access_token='. $token, 'post', $args);

        } catch(FacebookApiException $e){
            echo "Error:" .$e;
        }
        unlink($uploadfile);
        echo "Success!\n";
    } else {
        echo "Wrong file type!\n";
    }
}

?>

这篇关于如何使用html文件选择器(输入类型=“文件”)将照片上传到Facebook(图形api)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 15:46