Services
PHP code
Below is a script we wrote for testing POST and GET callbacks from Snipshot Services. You are free to use it but we cannot guarantee whatsoever that it will work on your server.
Sample PHP code
<?
//
//Snipshot callback test
//
//Install this script on your server to test and debug callbacks from
//www.snipshot.com. Note: this script will need read and write access
//to your image directory.
//CHANGE THIS TO THE DIRECTORY WHERE YOUR IMAGES WILL BE SAVED
$IMG_DIR = './';
chdir($IMG_DIR);
//CHANGE THIS TO THE NAME OF THE FIELD THAT CARRIES THE IMAGE DATA OR URL
$OUTPUT = 'snipshot_output';
function print_pre($r, $desc=''){
echo '<pre>' . $desc . ' ' . print_r($r) . '</pre>';
}
function glob_rsort_modtime( $patt ) {
if ( ( $files = @glob($patt, GLOB_BRACE) ) === false )
return array(false, 'Glob error.');
if ( !count($files) )
return array(false, 'No files found.');
$rtn = array();
foreach ( $files as $filename )
$rtn[$filename] = filemtime($filename);
arsort($rtn);
reset($rtn);
foreach ( $rtn as $filename => $t )
$rtn[$filename] = date('r', $t);
return $rtn;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Snipshot callback test</title>
<meta name="author" content="Greg Dingle">
</head>
<body>
<h2><a href="http://snipshot.com">Snipshot</a> callback test</h2>
<form name="form1" method="post" action="" enctype="multipart/form-data">
Manual upload:
<input type="file" name="<?=$OUTPUT?>">
<input type="submit" value="Upload">
</form>
<?
if (!empty($_REQUEST)){
print_pre($_REQUEST, 'REQUEST');
if (!empty($_FILES)){ //snipshot_callback_agent=snipshot
print_pre($_FILES[$OUTPUT], 'FILES');
move_uploaded_file(
$_FILES[$OUTPUT]['tmp_name'],
$_FILES[$OUTPUT]['name']
);
}
else if (!empty($_GET[$OUTPUT])){ //snipshot_callback_agent=user
$data = file_get_contents($_GET[$OUTPUT]);
$fp = fopen(basename($_GET[$OUTPUT]), 'w');
fwrite($fp, $data);
fclose($fp);
}
}
$file_list = glob_rsort_modtime('{*.jpg,*.png,*.gif,*.tif,*.psd,*.pdf}');
$file_list = array_slice($file_list, 0, 10);
print_pre($file_list, 'LAST 10 IMAGES');
foreach($file_list as $fn => $mt){
echo '<p><img src="'.$fn.'"/>';
}
?>
</body>
</html>
If you have any questions about this sample code, email us at help@snipshot.com.