我試圖讓用戶使用下面的PHPFacebook的 - 不能使用<INPUT TYPE =「文件」>標籤
<?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
}
?>
上傳從我的Facebook應用程序上傳圖片文件,但是當我執行這個代碼並且用戶按下「上傳」按鈕,$ _FILES ['file1'] ['name']的值變爲空白。
這段代碼在Facebook應用程序允許的?如果不是什麼是上傳文件的正確方法?
感謝
編輯
好了,所以這個問題是與Facebook。他們從任何請求中刪除所有文件標籤!建議我們使用iframe代替!
感謝大家的幫助!
嘿,我正要告訴你,我有與我自己的應用程序相同的問題我認爲問題是常規的應用程序頁面通過FB過濾,他們不想讓用戶上傳文件到他們的服務器然後必須將文件傳遞到您的服務器。 – 2009-08-11 21:39:54
有人可以精心製作這個嗎?這是否意味着在應用程序設置空間中將應用程序設置爲「iframe」與「fbml」,或者這是否意味着爲整個頁面調用?或只是爲了表格?我很樂意爲我解決這個問題! –
2009-10-07 21:44:02
您可以將包含表單的HTML放入iframe中。多數民衆贊成我是如何工作的。 – lostInTransit 2009-10-08 04:45:40