Exemple #1
0
// Just call the function!
$debugData = '';
$destDir = '../your_directory/images';
$maxFiles = 5;
// Max number of files accepted in the dest dir
// First, check if we don't have too much files. Not a bad test: since we fix the max size of files, the max total size of the files
// is under control.
$files = scandir($destDir);
$files = array_slice($files, 2);
// Shift out . and ..
while (count($files) > $maxFiles) {
    $file = array_shift($files);
    echo $file . " to remove\n";
    unlink($destDir . '/' . $file);
}
$result = HandleUploadedFile('image', $destDir, array('png', 'gif', 'jpg', 'jpeg'));
if ($debugData != '') {
    echo "<p><b>Debug data:</b><br>{$debugData}</p>\n";
}
if ($result[0] == '') {
    echo "<p><b>Error:</b> {$result[1]}</p>\n";
} else {
    $imageURL = 'http://' . $_SERVER['SERVER_NAME'] . '/your_directory/images/' . $result[0];
    echo "<p>Received image: <img src='{$imageURL}' alt='{$result[0]}' title='{$result[1]}'></p>\n";
    echo "<p>Posting to Facebook now</p>\n";
    $photo_details = array();
    $photo_details['url'] = $imageURL;
    $postdata = http_build_query($photo_details);
    $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
    $context = stream_context_create($opts);
    $post_url = "https://graph.facebook.com/" . $album_id . "/photos?access_token=" . $access_token;
Exemple #2
0
// First, check if we don't have too much files. Not a bad test: since we fix the max size of files, the max total size of the files
// is under control.

$files = @scandir($destDir); 
if(is_array($files)){
	$files = array_slice($files, 2);    // Shift out . and ..
	while (count($files) > $maxFiles)
	{
	    $file = array_shift($files);
	    echo $file . " to remove\n";
	    unlink($destDir . '/' . $file);
	}
}
*/

$result = HandleUploadedFile($title, './'.$destDir, array('png', 'gif', 'jpg', 'jpeg', 'pdf','ps','tiff','tif', 'txt'));
/*
if ($debugData != '')
{
    echo "<p><b>Debug data:</b><br>$debugData</p>\n";
}
*/
if ($result[0] == '')
{
    echo "<p><b>Error:</b> {$result[1]}</p>\n";
}
else
{
    $imageURL = 'http://' . $_SERVER['SERVER_NAME'] . $rootDir . $destDir . $result[0];
    echo $imageURL;
}