I wrote a Facebook app in PHP and need to be able to allow the user to upload an image to my server. I have used this code:
<?php
include_once('facebook.php');
$appapikey = 'API KEY HERE';
$appsecret = 'SECRET KEY HERE';
$facebook = new Facebook($appapikey, $appsecret);
$fb_user = $facebook->require_login();
if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
$filename = basename($_FILES['uploaded_file']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") &&
($_FILES["uploaded_file"]["size"] < 350000)) {
$newname = dirname(__FILE__).'/upload/zbt_'.$fb_user.'.jpg';
if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
header("Location: http://majik.zbrowntechnology.info/display.php");
} else {
header("Location: home.php?Fatal");
}
} else {
header("Location: home.php?Fatal");
}
} else {
header("Location: home.php?Fatal");
}
?>
but am not able to actually save the file in the directory. I have done some playing around with the code and think the problem lies in the moving of the file in this line:
if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {....