Facebook - 无法使用< input type =“file”>标签 [英] Facebook - cannot upload file using the <input type="file"> tag

查看:197
本文介绍了Facebook - 无法使用< input type =“file”>标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让用户使用以下php从我的Facebook应用程序上传图像

I am trying to let the user upload an image from my facebook app using the following php

<?php
echo render_header('Your');

define("MAX_SIZE", "1536");

function getExtension($str){
  $i = strpos($str,".");
  if(!$i) {return "";}
  $l = strlen($str) - $i;
  $ext = substr($str, $i+1, $l);
  return $ext;
}

$errors = 0;

if(isset($_POST['Upload'])){
  $image = $_FILES["file1"]["name"];
  if($image){
    $filename = stripslashes($_FILES["file1"]["name"]);
    $extension = getExtension($filename);
    $extension = strtolower($extension);
    if((strcasecmp($extension,"jpg") != 0) && (strcasecmp($extension,"jpeg") != 0) && (strcasecmp($extension,"png") != 0) && (strcasecmp($extension,"gif") != 0))
    {
      $errors = 1; 
    }
    else{
      $size = filesize($_FILES['file1']['tmp_name']);
      if($size > MAX_SIZE*1024){
        $errors = 2;
      }
      else{
        $image_name = md5(uniqid()) . '.' . $extension;
        $newname = "../images/" . $image_name;
        $flName = "/images/" . $image_name;
        $copied = move_uploaded_file($_FILES['file1']['tmp_name'], $newname);
        if(!$copied){
          $errors = 3;
        }
      }
    }
  }
}

if(isset($_POST['Upload']) && $errors == 0){
  //add to database here
  ...
  if($errors == 0){
    include "uploadedFile.php";
  }
}
else{

$user_details = $fb->api_client->users_getInfo($user, 'first_name,last_name,pic_square');
$image_url = $user_details[0]['pic_square'];
if($image_url == ""){
  $image_url = "http://static.ak.fbcdn.net/pics/q_silhouette.gif";
}
$user_name = $user_details[0]['first_name'] . " " . $user_details[0]['last_name'];
if(isset($_POST['Upload']) && $errors == 0){
?>
<div id="error" class="error">
<h2 id="standard_error" name="standard_error">Failed to upload tattoo.</h2>
<p id="standard_explanation" name="standard_explanation">
Error uploading file. This error occurred because either the photo was a size we don't support or there was a problem with the image file.
<br/>
</p>
</div>
<?php 
}
?>
<div id="newalbum" align="center">
<form id="upload" enctype="multipart/form-data" name="upload" action="" method="post">
<table class="formtable" cellspacing="0" border="0">
<tbody>
<tr class="tallrow">
<td class="label">
Upload Image:
<br/>
<small>
You can upload
<br/>
JPG, GIF or PNG
<br/>
files.
</small>
</td>
<td>
<div id="files">
<div id="1">
<input id="file1" class="inputfile" type="file" name="file1" size="22"/>
</div>
</div>
</td>
</tr>
</tbody>
</table>
<div class="formbuttons">
<input id="" class="inputbutton" type="submit" value="Upload Tattoo" name="Upload" />
<br/>
<small>The file size limit 1.5 MB. If your upload does not work, try uploading a smaller picture.</small>
<br/>
</div>
<?php
}
?>

但是,当我执行此代码,用户按上传按钮时,$ _FILES的值['file1'] ['name']出来是空白的。

But when I execute this code and the user presses the "Upload" button, the value of $_FILES['file1']['name'] comes out to be blank.

这个代码是否允许在Facebook应用程序中?如果不是上传文件的正确方法?

Is this code permissible in Facebook apps? If not what is the correct way to upload files?

感谢

编辑

好,所以问题是用Facebook。他们从任何请求中删除所有文件标签!建议我们使用iframe代替!

Ok so the problem is with facebook. They strip out all file tags from any request! It is suggested that we use iframes instead!

感谢大家的帮助。

推荐答案

确定。发现问题。在发送请求之前,Facebook将剥离所有文件标签。解决方案是使用iframe。

Ok. Found the problem. Facebook strips all file tags before sending in a request. The solution is to use iframes instead.

这篇关于Facebook - 无法使用&lt; input type =“file”&gt;标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆