i am encrypting my pdf but when i open it and enters the password it always says wrong error this is my code:
global $_dompdf_show_warnings;
global $_dompdf_debug;
global $_DOMPDF_DEBUG_TYPES;
$outfile = $id . '_qr_codes.pdf';
$save_file = TRUE; // Save the file or not
$buff = $this->qr_generate_pdf($id);
//echo $buff; die;
$dompdf = new DOMPDF();
$dompdf->load_html($buff);
if (isset($base_path)) {
$dompdf->set_base_path($base_path);
}
$dompdf->render();
$dompdf->get_canvas()->get_cpdf()->setEncryption('admin','ownerpass');
if ($_dompdf_show_warnings) {
global $_dompdf_warnings;
foreach ($_dompdf_warnings as $msg) {
echo $msg . "\n";
}
echo $dompdf->get_canvas()->get_cpdf()->messages;
flush();
}
if ($save_file) {
// if ( !is_writable($outfile) )
// throw new DOMPDF_Exception("'$outfile' is not writable.");
if (strtolower(DOMPDF_PDF_BACKEND) == "gd") {
$outfile = str_replace(".pdf", ".png", $outfile);
}
list($proto, $host, $path, $file) = explode_url($outfile);
if ($proto != "") // i.e. not file://
$outfile = $file; // just save it locally, FIXME? could save it like wget: ./host/basepath/file
//$outfile = dompdf_realpath($outfile);
// if ( strpos($outfile, DOMPDF_CHROOT) !== 0 )
// throw new DOMPDF_Exception("Permission denied.");
file_put_contents($outfile, $dompdf->output(array("compress" => 0)));
}
if (!headers_sent())
$dompdf->stream($outfile);
}
when i enter the password 'ownerpass' in the downloaded pdf it throughs an error-> The Password is incorrect. Please make sure that capslock is not on by mistake,and try again.
Thanks in advance
Related
Im trying to connect with my ssh server and download a file but i got a problem and i don't understand why. The file exist for sure, i search on internet but i didn't find anything to unbug this.
Error:
COPY ERROR: 2
ssh2_scp_recv() [function.ssh2-scp-recv]: Unable to receive remote file
My code:
public function ajaxdownloadfileAction() {
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$this->view->lib = $this->_labelsFile;
$connection = ssh2_connect($this->_configFile->ftp->hostname, $this->_configFile->ftp->port);
if ($connection) {
$login = ssh2_auth_password($connection, $this->_configFile->ftp->login, $this->_configFile->ftp->password);
if ($login) {
$content = true;
if ($content) {
$local = ' C:\Users\Public\Downloads ';
$fileName = "\\Talend\\PEC_DF6\\FluxSortantAdmissionPEC\\ARCHIVES\\XML\\wzadyyyy.0001054581.ap.xml";
if(!#ssh2_scp_recv($connection,$fileName,$local)){
$errors= error_get_last();
echo "COPY ERROR: ".$errors['type'];
echo "<br />\n".$errors['message'];
}
else {
echo "File copied from remote!";
}
//$filename = $this->getRequest()->getParam('name');
// $fileName = "\\Talend\\PEC_DF6\\FluxSortantAdmissionPEC\\ARCHIVES\\XML\\wzadyyyy.0001054581.ap.xml";
//$fileName = $this->_getParam('fileName');
//echo $fileName;die;
//ssh2_scp_recv($connection,$filename,$local);
}
$connection = null; unset($connection);
}
}
/* $result['status'] = 'OK';
$result['message'] = 'LE ficheir a bien ete telecharger';
echo json_encode($result);*/
}
I am using php sdk provided by Dropbox Core API. I have a minor bug... My file is being redirected all the time even I click on the allow button... Below is my index file:
index.php
<?php
session_start();
ini_set("display_errors",1);
require_once __DIR__.'/dropbox-sdk/Dropbox/strict.php';
$appInfoFile = __DIR__."/AppInfo.json";
// NOTE: You should be using Composer's global autoloader. But just so these examples
// work for people who don't have Composer, we'll use the library's "autoload.php".
require_once __DIR__.'/dropbox-sdk/Dropbox/autoload.php';
use \Dropbox as dbx;
$requestPath = init();
echo "Request path = ".$requestPath."<br>";
if ($requestPath === "/") {
$dbxClient = getClient();
if ($dbxClient === false) {
echo "Path: ".getPath("dropbox-auth-start")."<br>";die;
header("Location: ".getPath("dropbox-auth-start"));
exit;
}
$path = "/";//Debug completed
if (isset($_GET['path'])) $path = $_GET['path'];
$entry = $dbxClient->getMetadataWithChildren($path);
echo "Client<pre>";
print_r($dbxClient);
echo "</pre>";
echo "Entry".$entry;die;
if ($entry['is_dir']) {
echo renderFolder($entry);
}
else {
echo renderFile($entry);
}
}
else if ($requestPath == "/download") {
//die("Download");
$dbxClient = getClient();
if ($dbxClient === false) {
header("Location: ".getPath("dropbox-auth-start"));
exit;
}
if (!isset($_GET['path'])) {
header("Location: ".getPath(""));
exit;
}
$path = $_GET['path'];
$fd = tmpfile();
$metadata = $dbxClient->getFile($path, $fd);
header("Content-Type: $metadata[mime_type]");
fseek($fd, 0);
fpassthru($fd);
fclose($fd);
}
else if ($requestPath === "/upload") {
//die("Upload");
if (empty($_FILES['file']['name'])) {
echo renderHtmlPage("Error", "Please choose a file to upload");
exit;
}
if (!empty($_FILES['file']['error'])) {
echo renderHtmlPage("Error", "Error ".$_FILES['file']['error']." uploading file. See <a href='http://php.net/manual/en/features.file-upload.errors.php'>the docs</a> for details");
exit;
}
$dbxClient = getClient();
$remoteDir = "/";
if (isset($_POST['folder'])) $remoteDir = $_POST['folder'];
$remotePath = rtrim($remoteDir, "/")."/".$_FILES['file']['name'];
$fp = fopen($_FILES['file']['tmp_name'], "rb");
$result = $dbxClient->uploadFile($remotePath, dbx\WriteMode::add(), $fp);
fclose($fp);
$str = print_r($result, TRUE);
echo renderHtmlPage("Uploading File", "Result: <pre>$str</pre>");
}
else if ($requestPath === "/dropbox-auth-start") {
//die("dropbox-auth-start");
$authorizeUrl = getWebAuth()->start();
header("Location: $authorizeUrl");
}
else if ($requestPath === "/dropbox-auth-finish") {
//die("dropbox-auth-finish");
try {
list($accessToken, $userId, $urlState) = getWebAuth()->finish($_GET);
// We didn't pass in $urlState to finish, and we're assuming the session can't be
// tampered with, so this should be null.
assert($urlState === null);
}
catch (dbx\WebAuthException_BadRequest $ex) {
respondWithError(400, "Bad Request");
// Write full details to server error log.
// IMPORTANT: Never show the $ex->getMessage() string to the user -- it could contain
// sensitive information.
error_log("/dropbox-auth-finish: bad request: " . $ex->getMessage());
exit;
}
catch (dbx\WebAuthException_BadState $ex) {
// Auth session expired. Restart the auth process.
header("Location: ".getPath("dropbox-auth-start"));
exit;
}
catch (dbx\WebAuthException_Csrf $ex) {
respondWithError(403, "Unauthorized", "CSRF mismatch");
// Write full details to server error log.
// IMPORTANT: Never show the $ex->getMessage() string to the user -- it contains
// sensitive information that could be used to bypass the CSRF check.
error_log("/dropbox-auth-finish: CSRF mismatch: " . $ex->getMessage());
exit;
}
catch (dbx\WebAuthException_NotApproved $ex) {
echo renderHtmlPage("Not Authorized?", "Why not?");
exit;
}
catch (dbx\WebAuthException_Provider $ex) {
error_log("/dropbox-auth-finish: unknown error: " . $ex->getMessage());
respondWithError(500, "Internal Server Error");
exit;
}
catch (dbx\Exception $ex) {
error_log("/dropbox-auth-finish: error communicating with Dropbox API: " . $ex->getMessage());
respondWithError(500, "Internal Server Error");
exit;
}
// NOTE: A real web app would store the access token in a database.
$_SESSION['access-token'] = $accessToken;
echo renderHtmlPage("Authorized!",
"Auth complete, <a href='".htmlspecialchars(getPath(""))."'>click here</a> to browse.");
}
else if ($requestPath === "/dropbox-auth-unlink") {
//die("dropbox-auth-unlink");
// "Forget" the access token.
unset($_SESSION['access-token']);
echo renderHtmlPage("Unlinked.",
"Go back <a href='".htmlspecialchars(getPath(""))."'>home</a>.");
}
else {
//die("else part");
echo renderHtmlPage("Bad URL", "No handler for $requestPath");
exit;
}
function renderFolder($entry)
{
// TODO: Add a token to counter CSRF attacks.
$upload_path = htmlspecialchars(getPath('upload'));
$path = htmlspecialchars($entry['path']);
$form = <<<HTML
<form action='$upload_path' method='post' enctype='multipart/form-data'>
<label for='file'>Upload file:</label> <input name='file' type='file'/>
<input type='submit' value='Upload'/>
<input name='folder' type='hidden' value='$path'/>
</form>
HTML;
$listing = '';
foreach($entry['contents'] as $child) {
$cp = $child['path'];
$cn = basename($cp);
if ($child['is_dir']) $cn .= '/';
$cp = htmlspecialchars($cp);
$link = getPath("?path=".htmlspecialchars($cp));
$listing .= "<div><a style='text-decoration: none' href='$link'>$cn</a></div>";
}
return renderHtmlPage("Folder: $entry[path]", $form.$listing);
}
function getAppConfig()
{
global $appInfoFile;
try {
$appInfo = dbx\AppInfo::loadFromJsonFile($appInfoFile);
}
catch (dbx\AppInfoLoadException $ex) {
throw new Exception("Unable to load \"$appInfoFile\": " . $ex->getMessage());
}
$clientIdentifier = "examples-web-file-browser";
$userLocale = null;
return array($appInfo, $clientIdentifier, $userLocale);
}
function getClient()
{
if(!isset($_SESSION['access-token'])) {
return false;
}
list($appInfo, $clientIdentifier, $userLocale) = getAppConfig();
$accessToken = $_SESSION['access-token'];
return new dbx\Client($accessToken, $clientIdentifier, $userLocale, $appInfo->getHost());
}
function getWebAuth()
{
list($appInfo, $clientIdentifier, $userLocale) = getAppConfig();
$redirectUri = "http://localhost/MyApi/Dropbox/";//success.php";//getUrl("dropbox-auth-finish");
$csrfTokenStore = new dbx\ArrayEntryStore($_SESSION, 'dropbox-auth-csrf-token');
return new dbx\WebAuth($appInfo, $clientIdentifier, $redirectUri, $csrfTokenStore, $userLocale);
}
function renderFile($entry)
{
$metadataStr = htmlspecialchars(print_r($entry, true));
$downloadPath = getPath("download?path=".htmlspecialchars($entry['path']));
$body = <<<HTML
<pre>$metadataStr</pre>
Download this file
HTML;
return renderHtmlPage("File: ".$entry['path'], $body);
}
function renderHtmlPage($title, $body)
{
return <<<HTML
<html>
<head>
<title>$title</title>
</head>
<body>
<h1>$title</h1>
$body
</body>
</html>
HTML;
}
function respondWithError($code, $title, $body = "")
{
$proto = $_SERVER['SERVER_PROTOCOL'];
header("$proto $code $title", true, $code);
echo renderHtmlPage($title, $body);
}
function getUrl($relative_path)
{
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
$scheme = "https";
} else {
$scheme = "http";
}
$host = $_SERVER['HTTP_HOST'];
$path = getPath($relative_path);
return $scheme."://".$host.$path;
}
function getPath($relative_path)
{
if (PHP_SAPI === 'cli-server') {
return "/".$relative_path;
} else {
echo "Server values:<pre>";
print_r($_SERVER);
echo "</pre>";
return $_SERVER["SCRIPT_NAME"]."/".$relative_path;
}
}
function init()
{
global $argv;
// If we were run as a command-line script, launch the PHP built-in web server.
if (PHP_SAPI === 'cli') {
launchBuiltInWebServer($argv);
assert(false);
}
if (PHP_SAPI === 'cli-server') {
// For when we're running under PHP's built-in web server, do the routing here.
return $_SERVER['SCRIPT_NAME'];
}
else {
// For when we're running under CGI or mod_php.
if (isset($_SERVER['PATH_INFO'])) {
return $_SERVER['PATH_INFO'];
} else {
return "/";
}
}
}
function launchBuiltInWebServer($argv)
{
// The built-in web server is only available in PHP 5.4+.
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
fprintf(STDERR,
"Unable to run example. The version of PHP you used to run this script (".PHP_VERSION.")\n".
"doesn't have a built-in web server. You need PHP 5.4 or newer.\n".
"\n".
"You can still run this example if you have a web server that supports PHP 5.3.\n".
"Copy the Dropbox PHP SDK into your web server's document path and access it there.\n");
exit(2);
}
$php_file = $argv[0];
if (count($argv) === 1) {
$port = 5000;
} else if (count($argv) === 2) {
$port = intval($argv[1]);
} else {
fprintf(STDERR,
"Too many arguments.\n".
"Usage: php $argv[0] [server-port]\n");
exit(1);
}
$host = "localhost:$port";
$cmd = escapeshellarg(PHP_BINARY)." -S ".$host." ".escapeshellarg($php_file);
$descriptors = array(
0 => array("pipe", "r"), // Process' stdin. We'll just close this right away.
1 => STDOUT, // Relay process' stdout to ours.
2 => STDERR, // Relay process' stderr to ours.
);
$proc = proc_open($cmd, $descriptors, $pipes);
if ($proc === false) {
fprintf(STDERR,
"Unable to launch PHP's built-in web server. Used command:\n".
" $cmd\n");
exit(2);
}
fclose($pipes[0]); // Close the process' stdin.
$exitCode = proc_close($proc); // Wait for process to exit.
exit($exitCode);
}
?>
FYI: in my dropbox app I have set the redirect uri as : "localhost/MyApi/Dropbox/"... But it is going like loop... Can any one solve this? I thought to change the redirect uri to success.php but is there any other way to solve this?
Update:
I am also pasting my success.php file:
success.php
<?php
session_start();
ini_set("display_errors",1);
# Include the Dropbox SDK libraries
require_once "dropbox-sdk/Dropbox/autoload.php";
use \Dropbox as dbx;
$dbxClient = new dbx\Client($_SESSION['access-token'], "PHP-PicPixa/1.0");//This line is giving error
$accountInfo = $dbxClient->getAccountInfo();
echo "Account Info:<pre>";
print_r($accountInfo);
echo "</pre>";
$f = fopen("working-draft.txt", "a");
$result = $dbxClient->uploadFile("/working-draft.txt", dbx\WriteMode::add(), $f);
fclose($f);
print_r($result);
$folderMetadata = $dbxClient->getMetadataWithChildren("/");
print_r($folderMetadata);
$f = fopen("working-draft.txt", "w+b");
$fileMetadata = $dbxClient->getFile("/working-draft.txt", $f);
fclose($f);
echo "<br>File meta data:<br><pre>";
print_r($fileMetadata);
echo "</pre>";
?>
To access my full project please download it from: https://www.dropbox.com/sh/ps90blb2uujbxxh/AABdbU39upJSOeiLwxSnjufFa
Thank You,
It looks like you commented out code that would have redirected to dropbox-auth-finish. Since you're never going there, you're never finishing the auth process and never setting $_SESSION['access-token'] to anything.
I have a getPass.php which creates a Pass instance. Here is the code:
//create new pass instance
$coupon = new Pass("pass/source");
//fill in dynamic data
$coupon->content['serialNumber'] = (string)uniqid();
$coupon->content['coupon']['secondaryFields'][0]['value'] =
(string)$_POST['name'];
$coupon->content['locations'][0] =
$locations[(int)$_POST['location']];
$coupon->writePassJSONFile();
$coupon->writeRecursiveManifest();
$coupon->writeSignatureWithKeysPathAndPassword("pass", '12345');
$fileName = $coupon->writePassBundle();
echo "File saved to - $fileName";
**/* THIS IS WHERE IM TRYING TO PRESENT IT */**
$this->outputPassBundleAsWebDownload($fileName);
Then Pass.php does a lot of stuff, which works because Ive used it for emailing working passes but Im replacing the emailing functionality with the presentation/download functionality. So here is the code for Pass.php:
<?php
class Pass {
private $workFolder = null;
private $ID = null;
var $content = null;
var $passBundleFile = null;
private function copySourceFolderFilesToWorkFolder($path) {
//recurse over contents and copy files
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path),
RecursiveIteratorIterator::SELF_FIRST);
foreach($files as $name => $fileObject){
if (is_file($name) &&
substr($fileObject->getFileName(), 0, 1)!=".") {
copy($name,
$this->workFolder."/".str_replace($path."/", "",$name));
} else if (is_dir($name)) {
mkdir($this->workFolder."/".
str_replace($path."/", "",$name));
}
}
}
//import a json file into the object
function readPassFromJSONFile($filePath) {
//read the json file and decode to an object
$this->content =
json_decode(file_get_contents($filePath),true);
}
//export a json file from the object
function writePassJSONFile() {
file_put_contents($this->workFolder."/pass.json",
json_encode($this->content));
}
//generate the manifest file
function writeRecursiveManifest() {
//create empty manifest
$manifest = new ArrayObject();
//recurse over contents and build the manifest
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($this->workFolder),
RecursiveIteratorIterator::SELF_FIRST);
foreach($files as $name => $fileObject){
if (is_file($name) &&
substr($fileObject->getFileName(), 0, 1)!=".") {
$relativeName = str_replace($this->workFolder.
"/","",$name);
$sha1 = sha1(file_get_contents(
$fileObject->getRealPath()
));
$manifest[$relativeName] = $sha1;
}
}
//printf debug
// print_r($manifest);
//write the manifest file
file_put_contents($this->workFolder."/manifest.json",
json_encode($manifest));
}
//generate the bundle signature
function writeSignatureWithKeysPathAndPassword($keyPath, $pass) {
$keyPath = realpath($keyPath);
if (!file_exists($keyPath.'/WWDR.pem'))
die("Save the WWDR certificate as
$keyPath/WWDR.pem");
if (!file_exists($keyPath.'/passcertificate.pem'))
die("Save the pass certificate as
$keyPath/passcertificate.pem");
if (!file_exists($keyPath.'/passkey.pem'))
die("Save the pass certificate key as
$keyPath/passkey.pem");
$output = shell_exec("openssl smime -binary -sign". " -certfile '".$keyPath."/WWDR.pem'".
" -signer '".$keyPath."/passcertificate.pem'".
" -inkey '".$keyPath."/passkey.pem'".
" -in '".$this->workFolder."/manifest.json'".
" -out '".$this->workFolder."/signature'".
" -outform DER -passin pass:'$pass'");
}
//signature debugging
//print(file_get_contents($this->workFolder."/signature"));
//create the zip bundle from the pass files
function writePassBundle() {
//1 generate the name for the .pkpass file
$passFile = $this->workFolder."/".$this->ID.".pkpass";
//2 create Zip class instance
$zip = new ZipArchive();
$success = $zip->open($passFile, ZIPARCHIVE::OVERWRITE);
if ($success!==TRUE) die("Can't create file $passFile");
//3 recurse over contents and build the list
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($this->workFolder),
RecursiveIteratorIterator::SELF_FIRST);
//4 add files to the archive
foreach($files as $name => $fileObject){
if (is_file($name) &&
substr($fileObject->getFileName(), 0, 1)!=".") {
$relativeName = str_replace($this->workFolder."/",
"",$name);
$zip->addFile($fileObject->getRealPath(), $relativeName);
}
}
//5 close the zip file
$zip->close();
//6 save the .pkpass file path and return it too
$this->passBundleFile = $passFile;
return $passFile;
}
//make new instance from a source folder
function __construct($path) {
assert(file_exists($path."/pass.json"));
$this->ID = uniqid();
$this->workFolder = sys_get_temp_dir()."/".$this->ID;
mkdir($this->workFolder);
assert(file_exists($this->workFolder));
$this->copySourceFolderFilesToWorkFolder($path);
$this->readPassFromJSONFile($this->workFolder."/pass.json");
}
//delete all auto-generated files in the temp folder
function cleanup()
{
//recurse over contents and delete files
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($this->workFolder),
RecursiveIteratorIterator::CHILD_FIRST);
foreach($files as $name => $fileObject){
if (is_file($name)) {
unlink($name);
} else if (is_dir($name)) {
rmdir($name);
}
}
rmdir($this->workFolder);
}
//cleanup the temp folder on object destruction
function __destruct() {
$this->cleanup();
}
**/* THIS I ADDED AS A NEW FUNCTION TO PRESENT/DOWNLOAD */
function outputPassBundleAsWebDownload($fileName) {
//dump the generated pass to the browser
header("Content-Type: application/vnd.apple.pkpass");
header("Content-Disposition: attachment; ".
"filename=".basename($this->$fileName));
header("Content-Transfer-Encoding: binary");
header("Content-Length: ". filesize($this->$fileName));
flush();
readfile($this->$fileName);**
}
}
?>
The thing is the pass isnt being presented. Its being created properly because I get the echo on the screen with the fileName. What am Im missing? Im calling the output function from the getPass.php and passing in the $fileName. Why isnt it working?
You need to comment out the line that echos the file name. Echoing content to the browser forces PHP to automatically generate headers for text output, so it can serve the text of your file name.
Once output to the browser has started, you cannot send additional headers. This is why your headers in your output pass bundle function are being ignored and your pass is not being downloaded.
I want to add some function to download my files that was uploaded some other day. i am not handy with php so i dont know how to add function and generate link for all listed files at time.
here is my php code:-
// Destination folder for downloaded files
$date = date('m.d.y');
mkdir("uploads/" . $date, 0777, true);
$upload_folder = 'uploads/' . $date;
// If the browser supports sendAsBinary () can use the array $ _FILES
if(count($_FILES)>0) {
if( move_uploaded_file( $_FILES['upload']['tmp_name'] , $upload_folder.'/'.$_FILES['upload']['name'] ) ) {
echo 'done';
}
exit();
} else if(isset($_GET['up'])) {
// If the browser does not support sendAsBinary ()
if(isset($_GET['base64'])) {
$content = base64_decode(file_get_contents('php://input'));
} else {
$content = file_get_contents('php://input');
}
$headers = getallheaders();
$headers = array_change_key_case($headers, CASE_UPPER);
if(file_put_contents($upload_folder.'/'.$headers['UP-FILENAME'], $content)) {
echo 'done';
}
exit();
}
I want to develop an app in php that I can link with a particular photo album in my Facebook profile (or with all my photos) in order to know the direct url link of each photo.
The idea is to make an php script who shows in chronological order my facebook photos like a presentation. Im php programmer, but I know nothing about Facebook integration API. So guys if you can suggest me ways to do this it will be nice. Sorry for my English. Thanks!
here is a class for retriving specific user profile pictures (PHP), you'll get the idea from it to create what you want:
<?php
class FBPicture {
public $uid;
public $dir;
public $type = 'large';
public function setUId ($id) {
$this->uid = $id;
}
public function setDir ($dir) {
$this->dir = $dir;
}
public function fetch ($_uid=null, $_dir=null, $_type=null) {
if ($_uid === null)
throw new CHttpException ('Facebook User ID or Username is not set.');
if ($_dir === null)
$_dir = '/storage/';
if ($_type === null)
$_type = 'large';
$this->uid = $_uid;
$this->dir = $_dir;
$this->type = $_type;
$dir = getcwd () . $this->dir;
$type = $this->type;
// request URI
$host = 'http://graph.facebook.com/' . $_uid;
$request = '/picture';
$type = '?type=' . $type;
$contents = file_get_contents ($host.$request.$type);
// create the file (check existance);
$file = 'fb_' . $uid . '_' . rand (0, 9999);
$ext = '.jpg';
if (file_exists ($dir)) {
if (file_exists ($dir.$file.$ext)) {
$file .= $dir.$file.'2'.$ext;
if ($this->appendToFile ($file, $contents)) {
return str_replace ($dir, '', $file);
}
} else {
$file = $dir.$file.$ext;
touch ($file);
if ($this->appendToFile ($file, $contents)) {
return str_replace ($dir, '', $file);
}
}
} else {
// false is returned if directory doesn't exist
return false;
}
}
private function appendToFile ($file, $contents) {
$fp = fopen ($file, 'w');
$retVal = fwrite ($fp, $contents);
fclose ($fp);
return $retVal;
}
}
// sample usage:
// $pic will be the filename of the saved file...
$pic = FBPicture::fetch('zuck', 'uploads/', 'large'); // get a large photo of Mark Zuckerberg, and save it in the "uploads/" directory
// this will request the graph url: http://graph.facebook.com/zuck/picture?type=large
?>