Reputation: 2290
I have a html file which select images from user's computer.code is given bellow
//index.php
<html>
<body>
<form enctype="multipart/form-data" action="http://localhost/uploader/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>
when the user clicked 'upload' button, user is redirected to uploader.php file. Code of the upload.php is given bellow
<?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";
}
}
?>
I have created a folde named 'uploads' in same directory. when the user upload a file it first uploaded to 'uploads' folder and then to facebook.
This work fine in localhost. But it doesn't work when it is in the server.It gives me 'Wrong file type!' message. Note that I have the write permission in my server for 'uploads' folder.
I tried to print the value of '$_FILES'.
print_r($_FILES);
It gives me this output
Array ( [photo] => Array ( [name] => TEST IMAGE.jpg [type] => [tmp_name] => [error] => 2 [size] => 0 ) )
Can anyone help me with this please?
Upvotes: 0
Views: 3526