10 December, 2009

DOWNLOAD FILE USING PHP

You can easily download file in your server using PHP.

You can use PHP's  copy() function or file_get_contents() and file_put_contents() functions or curl library to download file.

Here is some example for you :
COPY FUNCTION

  1. $file = "http://example.com/file.html";
  2. copy($file,"eshan.html"); 
file_get_contents and file_fut_contents
  1.   $file = "http://example.com/file.html";
  2. $file_data = file_get_contents($file); 
  3. file_put_contents("eshan.html",$file_data)
CURL
  1. $ch = curl_init($file);
  2. curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  3. curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
  4. $data = curl_exec($ch);
  5. $fp = fopen("dpt.php","w");
  6. fwrite($fp,$data);
ENJOY !!!

09 December, 2009

FTP AND ZIP WITH PHP

You can easily download a file from ftp and archive it using php.
Here is an example for you :

  1. $host = "your ftp host";
  2. $user = "your ftp username";
  3. $pass = "your ftp password";
  4. if (class_exists("ZipArchive"))
  5. {
  6.     $ftp = ftp_connect($host);
  7.     ftp_login($ftp,$user,$pass);
  8.    $zip = new ZipArchive;
  9.    if ($zip->open("test.zip") === true)
  10.    {
  11.         ftp_get($ftp,"eshan.php","index.php",FTP_ASCII);
  12.         $zip->addFile("eshan.php","eshan.php");
  13.         $zip->close();
  14.         unlink("eshan.php");
  15.         echo "ok";
  16.    }
  17.    else {echo "ERROR";}
  18. }
  19. else {echo "Very sad";}
  20. ?>
First we have connected with ftp server and by using ftp_get() function we have downloaded file.
By using addFile() method of ZipArchive class we have added downloaded file.
After that we have deleted downloaded file using unlink() function.

08 December, 2009

HELLO WORLD

Hi,
this is Eshan from Bangladesh. I am a new blogger and a student