how to: display newlines with echo
7 Dec
In order to use newlines with the echo command pass the -e flag
echo -e "hi\nmom"
7 Dec
In order to use newlines with the echo command pass the -e flag
echo -e "hi\nmom"
20 Sep
here’s a few functions that are required by some of my code / functions.
make_db_connection
function make_db_connection($conn_name, $conn_sql)
{global $site_access, $database_site_access;
$covert_this_str = "global \$" . $conn_name . " ;";
eval($covert_this_str);
$covert_this_str = "\$" . $conn_name . "= mysql_query(\$conn_sql,\$site_access ) or die(mysql_error());";//report_error(‘002′,’" . addslashes($conn_sql) . "’));";
//echo $conn_sql."<br />";
eval($covert_this_str);
// addKill($conn_name);
}
fixForDB
function fixForDB($item,$nonEmpty=0){
$item=trim($item);
if(empty($item)){$item=$nonEmpty;
}
if(isNaN($item)){
$item=”‘”.addslashes($item).”‘”;
}return $item;
}
isNaN
this isn’t a function of mine. I found it on the php.net manual site. if you wrote it, please let me know so i can give proper credit
function isNaN( $var ) {
return !ereg (“^[-]?[0-9]+([\.][0-9]+)?$”, $var);
}
5 Sep
here is the code for a Proof of concept i did a few months ago. Its a demo ffmpeg and ffmpeg-php video conversion system that will also generate thumbnails. you either upload a file to the server (for large files) or select the file to upload (small files).
the code is offered as is. Please note this is a first version POC so the code is choppy and theres functionality missing, probably also alot of beta testing code.
*update: wordpress converts some of the characters into invalid code, so download / copy the source file here
http://elsid.net/wp-content/uploads/2007/10/ffmpeg_convert.php.txt
*update: the file works on php5, on at least it did when i tested. change the folder / url path to whatever your using.
you can view the source below
<?php
//error_reporting(2047);
//setup directory vars
$url_dir = "/video-convert-alpha/";
$url_folder="uploads";
$upload_dir = realpath($url_folder)."/";//"";
$url_dir="http://".$_SERVER['HTTP_HOST'].$url_dir.$url_folder."/";//echo "uploads : ". $upload_dir;
function time_stamp()
{
return gmdate("YmdHis");
}
///my trusty old upload function
function upload_from_form($file_item)
{
global $_FILES, $upload_dir, $url_dir;
//echo "uploading<br>";
if (!empty($_FILES[$file_item]['name'])) {
//echo $_FILES[$file_item]['tmp_name'];if($_FILES[$file_item]['size']*1==0){
echo "File : ".$_FILES[$file_item]['name']." is either empty or exceeds the file size limit, please reduce the size of this document, check the file, or contact Greg to increase the limit";
return "%";
}else{$file_name = str_replace(" ", "_" , $_FILES[$file_item]['name']);
$file_name = str_replace("’", "_" ,$file_name);
$file_name = str_replace("\\", "_" ,$file_name);
$file_name = str_replace("#", "_" ,$file_name);
$file_name = str_replace("&", "_" ,$file_name);
$file_name = str_replace("\"", "_" ,$file_name);
$file_name = str_replace("(", "_" ,$file_name);
$file_name = str_replace(")", "_" ,$file_name);
$file_name = str_replace("@", "_" ,$file_name);
$file_name = str_replace("\$", "_" ,$file_name);
$file_name = str_replace("*", "_" ,$file_name);
$file_name = str_replace("~", "_" ,$file_name);
$file_name = str_replace("`", "_" ,$file_name);
$file_name = str_replace("+", "_" ,$file_name);
$file_name = str_replace("=", "_" ,$file_name);
$file_name = str_replace("|", "_" ,$file_name);
$file_name= time_stamp() . "_" . $file_name;if (!file_exists($upload_dir . $file_name)) {
$file_loc = copy($_FILES[$file_item]['tmp_name'], $upload_dir . $file_name);
} else {
$file_name = time_stamp() . "_" . $file_name;
$file_loc = copy($_FILES[$file_item]['tmp_name'], $upload_dir . $file_name);
}
if ($file_loc != false) {
$file_loc = $upload_dir . $file_name;return $file_loc;
} else {
echo "Could not find file : ".$_FILES[$file_item]['name'];
return "%";} }
} else {
echo "upload failed<br>";
return "%";
}}
$flvtool2Path=’/usr/bin/flvtool2′;
$ffmpegPath=’/usr/bin/ffmpeg’;
$qualitySettings=array(‘low’=>’-ar 22050 -ab 32′,’med’=>’-ab 48k -ac 1 -ar 44100 -deinterlace -nr 500 -croptop 4 -cropbottom 4 -cropleft 8 -cropright 8 -aspect 4:3 -r 25 -b 270k -me_range 25 -i_qfactor 0.71 -g 500′,’high’=>’-ab 64k -ac 2 -ar 44100 -deinterlace -nr 500 -croptop 4 -cropbottom 4 -cropleft 8 -cropright 8 -aspect 4:3 -r 25 -b 650k -me_range 25 -i_qfactor 0.71 -g 500′);
$reqFields="email|password|quality|size|format";
$reqFields=explode("|",$reqFields);
$filesMessage="";
$formatSettings=array(‘flv’=>’-f flv -acodec mp3′);$badSubmit=false;
//check for post
if(!empty($_POST['password'])){
//check for pass and user
//echo "checking pass<br>";
if(trim($_POST['password'])==’ricecrispytreat’ && !empty($_POST['email'])){
//check submission
//echo "password excepted<br>";
for($i=0;$i<count($reqFields);$i++){
if(empty($_POST[$reqFields[$i]])){
$badSubmit=true;
echo $reqFields[$i]." not completed<br>";
break;}
}
//ok we’ve done basic checking – now lets get to work
if(!$badSubmit){
//first lets make sure we have a file
if(!empty($_POST['serverPath']) || !empty($_FILES['fileUploaded'])){
if(!empty($_FILES['fileUploaded'])){$processFile=upload_from_form(‘fileUploaded’);
}else{
$processFile=$_POST['serverPath'];
$processFile=realpath($processFile);
if(!file_exists($processFile)){
$processFile="%";
}}
}else{
$processFile=’%';
}
if($processFile==’%'){
echo " either you have entered a non valid path, or your uploaded file wasn’t in the right format<br>";}
//end file checks
if($processFile!=’%'){
//now lets see if we have thumbnails to make
if(isset($_POST['useThumbs'])){
//echo "thumbnailing<br>";
//defaults
$maxThumbnails=5;
$thumbnailsFrom=1;//if they were set
if(!empty($_POST['thumbsMax'])){
$maxThumbnails=$_POST['thumbsMax'];
$maxThumbnails*=1;
}if(!empty($_POST['thumbStart'])){
$thumbnailsFrom=$_POST['thumbStart'];
$thumbnailsFrom*=1;
}
//echo "making thumbnails";
//lets do the work
//setup ffmpeg-php object, and needed vars
$ffmpegObj = new ffmpeg_movie($processFile);
$totalTime=$ffmpegObj->getDuration();
$frameRate=$ffmpegObj->getFrameRate();
$thumbIncrements=(($totalTime*$frameRate)-($thumbnailsFrom*$frameRate))/$maxThumbnails;
$wide=$ffmpegObj->getFrameWidth();
$high=$ffmpegObj->getFrameHeight();
$startFrame=$thumbnailsFrom*$frameRate;
//echo "frame rate: ".$frameRate;
$filesMessage.="ThumbNails can be viewed at :<p>";
//echo "thumbs being processed now";
for($t=0;$t<$maxThumbnails;$t++){
//$image= @imagecreatetruecolor($wide,$high);
$thumbFile=$processFile.".".$t.".png";
$currFrame=floor($startFrame+($thumbIncrements*$t));
//echo "<br>thumb of frame $currFrame: ".$thumbFile;
$thumb=$ffmpegObj->getFrame($currFrame);if ($thumb) {
$thumbImage = $thumb->toGDImage();
if ($thumbImage) {
imagepng($thumbImage,$thumbFile);
imagedestroy($thumbImage);
}
}
//echo "<br>saved";
$thumbUrl=$url_dir."".basename($thumbFile);
$filesMessage.="<a href=’".$thumbUrl."’>".$thumbUrl."</a><br>";}
$filesMessage.="</p>";}
//echo "outside thumbs";
$newFile=substr($processFile,0,strrpos($processFile,".")).".".$_POST['format'];
$ffmpegCall=$ffmpegPath." -i ".$processFile." ".$qualitySettings[$_POST['quality']]." ".$formatSettings[$_POST['format']]." -s ".$_POST['size']." ".$newFile;$flvtool2Call=flvtool2Path." -U stdin ".$newFile."";
$encodeCall=$ffmpegCall." | ".$flvtool2Call;
exec($encodeCall);
$fileUrl=$url_dir."".basename($newFile);
$filesMessage.="<p>You Can Now View / Download Your Video @<a href=’".$fileUrl."’>".$fileUrl."</a><br></p>";
$user=$_POST['email'];
mail($user,basename($newFile),$filesMessage);
$foo=@unlink($processFile);
//echo $fileMessage;
}
}}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#FF0000" bgcolor="#CCCCCC">
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td colspan="5"><font color="#ff0000"><?php echo $filesMessage;?></font></td>
</tr>
<tr>
<td colspan="5">video convert .01 alpha</td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3">this isn’t pretty, but it gets the job done. consider this a POC. More options to come, and maybe an ajax or flash interface. Probaly Flash</td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3">Access and reporting</td>
</tr>
<tr>
<td colspan="3"><label for="email">enter your email address </label>
<input type="text" name="email" id="email" />
<br />
This will be used to notify you once conversion has completed.</td>
</tr>
<tr>
<td colspan="3"><label for="password">Enter the video system password</label>
<input type="text" name="password" id="password" value=’ricecrispytreat’ /></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3">video file—</td>
</tr>
<tr>
<td><label for="serverPath">file server path</label>
<input type="text" name="serverPath" id="serverPath" /></td>
<td>or</td>
<td><label for="fileUploaded">upload file</label>
<input type="file" name="fileUploaded" id="fileUploaded" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="3">thumbnails</td>
</tr>
<tr>
<td><label for="label">Make thumbnails</label>
<input type="checkbox" name="useThumbs" id="useThumbs" />
<label for="useThumbs"></label></td>
<td><label for="thumbsMax">how many</label>
<input type="text" name="thumbsMax" id="thumbsMax" />
– defaults to 5 if not set</td>
<td><label for="thumbStart">from what postion</label>
<input type="text" name="thumbStart" id="thumbStart" />
<label for="thumbsMax"> (time in seconds) so 6:05 would be 6*60+5= 365 – defaults to 0 if not set</label></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3">video settings</td>
</tr>
<tr>
<td><label for="quality">Select quality</label>
<select name="quality" id="quality">
<option value="low">Low</option>
<option value="med">Medium</option>
<option value="high" selected="selected">High</option>
</select></td>
<td><label for="size">Select Size</label>
<select name="size" id="size">
<option value="160×120">160×120</option>
<option value="320×240" selected="selected">320×240</option>
<option value="480×360">480×360</option>
<option value="640×480">640×480</option>
<option value="720×480">720×480</option>
<option value="1024×768">1024×768</option>
<option value="1280×720">1280×720</option>
<option value="1280×1024">1280×1024</option>
<option value="1600×1200">1600×1200</option>
<option value="1920×1080">1920×1080</option>
</select> </td>
<td><label for="format">select format</label>
<select name="format" id="format">
<option value="flv" selected="selected">Flash Video</option>
</select> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Audio Settings</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><input type="checkbox" name="noVideo" id="noVideo" />
<label for="noVideo">Audio Only – not working yet</label></td>
<td> </td>
<td> </td>
</tr>
</table></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><label for="button"></label>
<input type="submit" name="button" id="button" value="Submit" /></td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
Hope this helps someone
31 Aug
Out of all the xml-rpc functions / classes etc out there i like this one the best. Why? its simple.
I’ll post a rewrite/ extended version once i get to it.
# Using the XML-RPC extension to format the XML package
$request = xmlrpc_encode_request(“weblogUpdates.ping”, array(“Copenhagen Ruby Brigade”, “http://copenhagenrb.dk/”) );# Using the cURL extension to send it off,
# first creating a custom header block
$header[] = “Host: rpc.technorati.com”;
$header[] = “Content-type: text/xml”;
$header[] = “Content-length: “.strlen($request) . “\r\n”;
$header[] = $request;$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, “http://rpc.technorati.com/rpc/ping”); # URL to post to
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); # return into a variable
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header ); # custom headers, see above
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, ‘POST’ ); # This POST is special, and uses its specified Content-type
$result = curl_exec( $ch ); # run!
curl_close($ch);echo $result;
check it out : http://snippets.dzone.com/posts/show/2596
12 Aug
if your updating your path and would like to activate the changes right away do . /etc/profile
:
a quick echo $PATH will display your updated path
11 Apr
So i bought my 8 gig nano, nike+, arm band, and modded my shoes.
Why you ask? Simple because then I’d be forced to think about running, hopefully to one day lead up to me actually running…. So far that theory has worked once, for 1 mile.
That mile kicked my ass. It was all uphill in the blistering sun, during a snow storm.
So much for being proactive
< ?php
echo ‘
?>