Tuesday, November 15, 2011

WYSIWYG Editor with image upload function for FREE !!!!!

Hey Guyz,

As we all know there's a one problem in free WYSIWYG editors (like Tiny MCE, etc) that do not have the image uploading facility.

normally what we are doing is giving the user to upload the file to server then copy the link and put it as the image url.

Here i have found a solution to upload the file within the WYSIWYG.

First download the OPEN WYSIWYG from http://www.openwebware.com/

Then download the file upload add-on to OPEN WYSIWYG Editor from here : http://www.gallagherwebsitedesign.com/scripts/openwysiwyg-file-upload-addon/

And follow the instructions mentioned in the above link.

Monday, September 12, 2011

Export / Import a Perticular table / database in Oracle using command prompt

Export:

To export, type this command in cmd:
>> exp user/password@instant
It will show many questions, leave it with default answer using hit enter. But, there are the important question, such as:
- (2)U(sers), or (3)T(ables): (2)U >
2 : to export all database under user that mentioned above
3 : to export selected tables only. If 3 choosed, it will appear question what tables that will be exported
- Export grants (yes/no): yes > (type Y or N)
- Export table data (yes/no): yes > (type Y or N)
- Compress extents (yes/no): yes > (type Y or N)

In the rest, make sure that appear message Export terminated successfully without warnings.

Import:

To import full dmp file type this command in cmd:
>> imp user/password@instant file=emp.dmp log=imp.log full=yes

To import dept table alone type this command in cmd:
>> imp user/password@instant file=emp.dmp log=imp.log fromuser=user touser=user tables=dept

FROMUSER and TOUSER clause are optional. But in case if used, then create a user in the destination database that is mentioned in TOUSER clause then try importing the dmp file.

In the rest, make sure that appear message Export terminated successfully without warnings.

Monday, July 18, 2011

Get the value of a radio buttton group using javascript

for (index=0; index < document.form1.del_add_choice.length; index++) {
if (document.form1.del_add_choice[index].checked) {
var radioValue = document.form1.del_add_choice[index].value;
break;
}

}
alert(radioValue);
return false;

Thursday, June 23, 2011

Check or get the anchor name

?>
$url = 'http://username:password@hostname/path?arg=value#anchor';
print_r(parse_url($url));
echo parse_url($url, PHP_URL_PATH);
?>

Monday, June 6, 2011

Use Gmail as your SMTP when sending emails - php

  1. Download PHPMailer from http://phpmailer.sourceforge.net
  2. Extract to folder phpmailer
  3. Create a file email.php
  4. Paste this code and change the values in blue as you need (I modified the sample code given on the PHPMailer homepage)

require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer(); 
$mail->IsSMTP(); // send via SMTP
IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "username@gmail.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$webmaster_email = "username@doamin.com"; //Reply to this email ID
$email="username@domain.com"; // Recipients email ID
$name="name"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Webmaster";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>

5. Open the file class.smtp.php in phpmailer directory
6. Paste this code
$host = "ssl://smtp.gmail.com";
$port = 465;
before the line 104 #connect to the smtp server
Hint: Search for #connect

7. Open this page in browser and it will send the email using GMail.

Hint: When you want to email the details from a form, set the variables using the form variables.
eg. $mail->Username=$_POST['email']

Thanks to : http://deepakssn.blogspot.com/2006/06/gmail-php-send-email-using-php-with.html

Tuesday, May 24, 2011

Get the first image only from a content - PHP

//This is the function, Replace your content to $content variable

function catch_that_image() {
  $content = "Add your content that having image";
  $first_img = '';
  ob_start();
  ob_end_clean();
  $output = preg_match_all('//i', $content, $matches);
  $first_img = $matches [1] [0];

  if(empty($first_img)){ //Defines a default image
    $first_img = "noimage.jpg"; //Give the path of noimage.jpg
  }
  return $first_img;
}

//And get the output by calling the function

echo  catch_that_image();

This is very useful when we have to get the content from the database that will have image inside the same field and when we wanted to grab the image for a thumbnail or something

Monday, May 23, 2011

File uploading script in php that's working 100%

Convert any HTML file to PDF using PHP

After i search for a whole day for a script to convert html to pdf on the fly i could found this script as an easy integrating working one, there may be more scripts, but i tried with lots they got some issues and errors, anyway this is 100% working.

############################################################################
Function to Convert any HTML file into PDF
Can save into a pdf file on server, or stream to the user's browser
If you want to stream to the browser: $objClass->fnURL2PDF("http://www.yahoo.com", "pdf.pdf");
If you want to save on the server: $objClass->fnURL2PDF("http://www.yahoo.com", "", "../folder/filename.pdf");
Usage: $objClass->fnURL2PDF("http://www.yahoo.com", "pdf.pdf"); Default is USA
############################################################################
function fnURL2PDF($varURL, $varFileName = "pdf.pdf", $varSavePath = "")
{
$varSocket = fsockopen("www.easysw.com", 80, $errno, $errstr, 1000);
if (!$varSocket) die("$errstr ($errno)\n");

fwrite($varSocket, "GET /htmldoc/pdf-o-matic.php?URL=" . $varURL . "&FORMAT=.pdf HTTP/1.0\r\n");
fwrite($varSocket, "Host: www.easysw.com\r\n");
fwrite($varSocket, "Referer: http://www.easysw.com/htmldoc/pdf-o-matic.php\r\n");
fwrite($varSocket, "\r\n");

$varHeaders = "";
while ($varStr = trim(fgets($varSocket, 4096)))
$varHeaders .= "$varStr\n";

$varBody = "";
while (!feof($varSocket))
$varBody .= fgets($varSocket, 4096);

if ($varSavePath != '')
{
// Save the File
$varFileHandle = @fopen($varSavePath,'w');
$varBytes = @fwrite($varFileHandle, $varBody);
}
else
{
//Download file
if(isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']) and strpos($HTTP_SERVER_VARS['HTTP_USER_AGENT'],'MSIE'))
Header('Content-Type: application/force-download');
else
Header('Content-Type: application/octet-stream');
if(headers_sent())
die('Some data has already been output to browser, can\'t send PDF file');
Header('Content-Length: '.strlen($varBody));
Header('Content-disposition: attachment; filename='.$varFileName);
echo $varBody;
}
return(true);
}

Source : http://smashscripts.blogspot.com/2007/06/php-convert-any-html-file-into-pdf.html

Thursday, April 28, 2011

Preview any file in the browser using Google Docs Viewer (No need to upload it to Google Docs)


Finally I could find a good way to preview the documents. It’s Google Docs Viewer (https://docs.google.com/viewer) (Not the google docs)

What we have to do is we have to just upload the file in our server and create the link in a different way and viewing it. So no need to upload the document to Google docs.

Follow is the test file that I checked with uploading the file to my server


Supporting Formats
  • Microsoft Word (.DOC and .DOCX)
  • Microsoft Excel (.XLS and .XLSX)
  • Microsoft PowerPoint (.PPT and .PPTX)
  • Adobe Portable Document Format (.PDF)
  • Apple Pages (.PAGES)
  • Adobe Illustrator (.AI)
  • Adobe Photoshop (.PSD)
  • Tagged Image File Format (.TIFF)
  • Autodesk AutoCad (.DXF)
  • Scalable Vector Graphics (.SVG)
  • PostScript (.EPS, .PS)
  • TrueType (.TTF)
  • XML Paper Specification (.XPS)

__________________________________________________________________________________


But we have to do change that url to http%3A%2F%2Fwww.asoftit.com%2FTestDoc.docx   (: = %3A  |   / = %2F  )

Use str_replace function in PHP to do this

Monday, April 25, 2011

Change the Collation of a database field by query


This will be very needful when it's come to different language having in your web site / system
ALTER TABLE MyTable ALTER COLUMN CharCol
            varchar(10)COLLATE Latin1_General_CI_AS NOT NULL
GO

Thursday, March 3, 2011

Tree View Generate - Recursive Function , Any number of depth

<?php
  $connect = mysql_connect("localhost", "root", "");
  mysql_select_db("test");
  $nav_query = mysql_query("SELECT * FROM `nodes` ORDER BY `id`");
  $tree = ""; // Clear the directory tree
  $depth = 10; // Child level depth.
  $top_level_on = 1; // What top-level category are we on?
  $exclude = array(); // Define the exclusion array
  array_push($exclude, 0); // Put a starting value in it
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  <html>
  <head>
  <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
  <title>Folder tree with Drag and Drop capabilities</title>
  <script type="text/javascript" src="js/ajax.js"></script>
  <script type="text/javascript" src="js/context-menu.js"></script><!-- IMPORTANT! INCLUDE THE context-menu.js FILE BEFORE drag-drop-folder-tree.js -->
  <script type="text/javascript" src="js/drag-drop-folder-tree.js">

 /************************************************************************************************************
  (C) www.dhtmlgoodies.com, July 2006

  Update log:

  This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.

  Terms of use:
  You are free to use this script as long as the copyright message is kept intact.

  For more detailed license information, see http://www.dhtmlgoodies.com/index.html?page=termsOfUse

  Thank you!

  www.dhtmlgoodies.com
  Alf Magne Kalleland

  ************************************************************************************************************/
  </script>
  <link rel="stylesheet" href="css/drag-drop-folder-tree.css" type="text/css"></link>
  <link rel="stylesheet" href="css/context-menu.css" type="text/css"></link>
  <style type="text/css">
  /* CSS for the demo */
  img{
  border:0px;
  }
  </style>
  <script type="text/javascript">
  //--------------------------------
  // Save functions
  //--------------------------------
  var ajaxObjects = new Array();

  // Use something like this if you want to save data by Ajax.
  function saveMyTree()
  {
  saveString = treeObj.getNodeOrders();
  var ajaxIndex = ajaxObjects.length;
  ajaxObjects[ajaxIndex] = new sack();
  var url = 'saveNodes.php?saveString=' + saveString;
  ajaxObjects[ajaxIndex].requestFile = url; // Specifying which file to get
  ajaxObjects[ajaxIndex].onCompletion = function() { saveComplete(ajaxIndex); } ; // Specify function that will be executed after file has been found
  ajaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function

  }
  function saveComplete(index)
  {
  alert(ajaxObjects[index].response);
  }



  // Call this function if you want to save it by a form.
  function saveMyTree_byForm()
  {
  document.myForm.elements['saveString'].value = treeObj.getNodeOrders();
  document.myForm.submit();
  }



</script>
  
  </head>
  <body>
  
  <?php
  while ( $nav_row = mysql_fetch_array($nav_query) )
  {
  $goOn = 1; // Resets variable to allow us to continue building out the tree.
  for($x = 0; $x < count($exclude); $x++ ) // Check to see if the new item has been used
  {
  if ( $exclude[$x] == $nav_row['id'] )
  {
  $goOn = 0;
  break; // Stop looking b/c we already found that it's in the exclusion list and we can't continue to process this node
  }
  }
  if ( $goOn == 1 )
  {

  $tree .= "<ul id='dhtmlgoodies_tree2' class='dhtmlgoodies_tree'><li id='node0' noDrag='true' noSiblings='true' noDelete='true' noRename='true'><a href='#'>".$nav_row['name']."</a>"; // Process the main tree node
  array_push($exclude, $nav_row['id']); // Add to the exclusion list
  if ( $nav_row['id'] < 50 )
  { $top_level_on = $nav_row['id']; }

  $tree .= build_child($nav_row['id']); // Start the recursive function of building the child tree
  }
  }


  function build_child($oldID) // Recursive function to get all of the children...unlimited depth
  {
  global $exclude, $depth; // Refer to the global array defined at the top of this script
  $child_query = mysql_query("SELECT * FROM `nodes` WHERE pid=" . $oldID);

  $available = mysql_num_rows($child_query);

  $i = 1 ;

  if($available > 0)
  $tempTree .= "<ul>";


  while ( $child = mysql_fetch_array($child_query) )
  {
  if ( $child['id'] != $child['pid'] )
  {
  for ( $c=0;$c<$depth;$c++ ) // Indent over so that there is distinction between levels
  {  }

$tempTree .= "<li id='node".$child['id']."' ><a href='#'>".$child['name']."</a>";

  $depth++; // Incriment depth b/c we're building this child's child tree  (complicated yet???)
  $tempTree .= build_child($child['id']); // Add to the temporary local tree
  $tempTree .= "</li>";
  $depth--; // Decrement depth b/c we're done building the child's child tree.
  array_push($exclude, $child['id']);// Add the item to the exclusion list
  }

  $i = $i + 1;
  }


if($available > 0)
  $tempTree .= "</ul>";


  return $tempTree; // Return the entire child tree
  }

  echo $tree."</li></ul>";

  ?>

  <form>
  <input type="button" onclick="saveMyTree()" value="Save">
  </Form>
  <script type="text/javascript">
  treeObj = new JSDragDropTree();
  treeObj.setTreeId('dhtmlgoodies_tree2');
  treeObj.setMaximumDepth(7);
  treeObj.setMessageMaximumDepthReached('Maximum depth reached'); // If you  to show a message when maximum depth is reached, i.e. on drop.
  treeObj.initTree();
  treeObj.expandAll();

  </script>
  <a href="#" onclick="treeObj.collapseAll()">Collapse all</a> |
  <a href="#" onclick="treeObj.expandAll()">Expand all</a>
  <p style="margin:10px">Use your mouse to drag and drop the nodes. Use the "Save" button to save your changes. The new structure will be sent to the server by use of Ajax(Asynchron XML and Javascript). </p>
  <p style="margin:10px"><b><i>Note!</i></b> I'm not saving the structure in this demo in order to make the script look the same for all visitors</p>

  <!-- Form - if you want to save it by form submission and not Ajax -->
  <form name="myForm" method="post" action="saveNodes.php">
  <input type="hidden" name="saveString">
  </form>


</body>
  </html>


Sunday, January 23, 2011

Check/Uncheck all checkboxes based on one check box

<script language='JavaScript'>
checked = false;
function checkedAll ()
{
if (checked == false)
{
checked = true
}
else{checked = false
}
for (var i = 0; i < document.getElementById('myform').elements.length; i++) {
document.getElementById('myform').elements[i].checked = checked;
}
}
</script>


<form id="myform">
<input type="checkbox" name="foo"/>
<input type="checkbox" name="bar"/>
<BR>Check all: <input type='checkbox' name='checkall' onclick='checkedAll();'> </form>

Tuesday, January 11, 2011

Upload video from any format and view your video in the site - With youtube API

You will need : Developer Key for Youtube you can request it from google code if you have register on youtube using your gmail id go to here and get http://code.google.com/apis/youtube/dashboard/gwt/index.html

And paste the you tube developer key in the ClassYouTubeAPI.php page
public $developerKey = "Your key";

And add your username and password of the youtube account in example.php page

$username ='Your username for youtube account';
$pass='Your password for youtube account';

Sometimes you may get the error saying "maximum execution timeout" , then what you have to do is go to the php.ini file and change the max_execution_time = 30 to something bigger, or you can put 0.

So i hope your headache to convert videos and upload to web sites is solved now


And do not forget it's having the functions to 


  • Create Play List
  • Delete Play list
  • Get Play lists
  • Get Videos by Play List Id
  • Add Video To Play List
  • DeleteVideo From Play List
  • Get Videos by Play List Id




Monday, January 10, 2011

Toggle Visibility - Javascript

Simply paste this javascript under the "<body>" tag

<script type="text/javascript">

<!--

function toggle_visibility(id) {

var e = document.getElementById(id);

if(e.style.display == 'block')

e.style.display = 'none';

else

e.style.display = 'block';

}

//-->

</script>




Example of executing it can see below



<a href="#" onclick="toggle_visibility('foo');">Click here to toggle visibility of element #foo</a>

<div id="foo">This is foo</div>

Monday, October 11, 2010

SQL - Like Query, Order the results according to the word density of the searched results

SELECT * FROm TestTable WHERE description LIKE '%environment%' order by description LIKE '%environment%' desc