Thursday, 6 October 2016

How to download audio file from any server in php

Download audio file from server using Curl

After so many efforts and time I have downloaded all the audio file from my server to local diectory.

Here is the code that I have written.I have a CSV file which contains all the links of the audio files

"http://www.dsdsdsdsd--/download/324324","2016-10-06"
"http:///www.dsdsdsdsd--/download/32qww4324","2016-10-06"

 .............................

...............................

Curl must me installed in your system.


First You need to parse this file to get the Url's then hit the URL using curl

<?php 

$file       = '/var/www/html/test/results.csv';
$fileData   = fopen($file,'r');
while($row = fgets($fileData)){ 

    $tempUrl         =  explode(",",$row);
    $tempFileNameArr = explode("/",$tempUrl[0]);
    //print_r($tempFileNameArr);
    $remoteFileName  = rtrim($tempFileNameArr[6],'"');
    
    $ch   = curl_init();
    echo $tempUrl[0];
    $url = trim($tempUrl[0],'"');
    $url = rtrim($url, '/\\');
    echo "FInal ULR::$url";
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    echo "Strlen is::".strlen(trim($tempUrl[0]));
    $fp = fopen($remoteFileName.'.mp3', 'w');

    // Set CURL to write to disk
    curl_setopt($ch, CURLOPT_FILE, $fp);

    // Execute download
    curl_exec ($ch);
    echo "status::".$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $output = '';
    if (curl_error($ch)){
        $output .= "\n". curl_error($ch);
    }
    echo $output;
    //echo "output".$output;
    curl_close ($ch);

    fclose($fp);

}
fclose($fileData);

?>



Problem faced:

1.Status 0 from curl request 

References:

1. https://curl.haxx.se/docs/manpage.html#-L

2.http://stackoverflow.com/questions/2392677/best-way-to-remove-trailing-slashes-in-urls-with-php


2. Status 301

Add this line will solve your problem


curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

http://stackoverflow.com/questions/21233771/php-curl-function-301-error


CURLOPT_FOLLOWLOCATION cannot be activated when 

in safe_mode or an open_basedir is set



Solution 1:

Set safe_mode = Off in your php.ini file (it's usually 
in /etc/ on the server). If that's already off, then look around for 
the open_basedir stuff in the php.ini file and comment that 
line (#open_basedir...). Restart apache server.




Tuesday, 6 September 2016

HOW TO CONFIGURE GIT COMMIT CREDENTIALS



You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

Wednesday, 10 August 2016

INSTALL FILEZILA IN UBUNTU 16.04 LTS

Here are some steps that need to be follow to install filezila in ubuntu 16.06 LTS

Hello Guys, Please follow the below steps to install filezila in your system

Step 1: Open you terminal

Step 2: Copy and paste the below line

sudo add-apt-repository ppa:adabbas/1stppa

Step 3:

sudo apt-get update

Step 4:

sudo apt-get install filezilla

Step 5: Click on the "Search You compute" option on top icon and Type FileZila

Step 6: Open it 

That's it.


Sunday, 31 July 2016

What is Database Seeding

What is Seeding
 
In the context of core data seeding just means shipping your app with a persistent store pre-filled with default data, that is necessary for the application. 

For Example your when your purchase a new mobile, it filled with some apps, tunes etc.

Database Seeding
 
Database seeding is the initial seeding of a database with some pre- filled data.

This is often an automated process that is executed upon the initial setup of an application.

The data can be dummy data or necessary data such as an initial administrator account.

Important Links:

https://en.wikipedia.org/wiki/Database_seeding

Sunday, 24 July 2016

Task Scheduling in Laravel

Scheduling Task In Laravel



In the past, developers have generated a Cron entry in the cron file 

for each task they need to schedule. However, this is a headache 

and time consuming task. Your task schedule is no longer in source 

control, and you must SSH into your server to add the Cron entries 

in the cron file. The Laravel command scheduler allows you to 

fluently and expressively define your command schedule within 

Laravel itself, and only a single Cron entry is needed on your 

server, it makes you very easy to control on you commands.


I will show the entire process of scheduling the task by an example,


which will insert logs every minute in log file. Please follow the 


steps and you are done with Task Scheduling



Step 1:


Inside you project folder type this below command




php artisan make:console LogDemo –command=log:demo



Step2:



go to /app/console/commands/


you will see a file names as logDemo.php that is your newly 


created file Open it and add the below line which will put log in the log file.



Log::info('Showing user profile for user');


Next task is to register this command so that kernel can actually 


know it.


Step3:


Open kernel.php file and add this line


Commands\LogDemo::class,


inside protected $commands = [ ];


After adding it will look like this



protected $commands = [


//Commands\Inspire::class,


 Commands\LogDemo::class,
];




Step 4:


4.1


  crontab -e


4.2 Add the below line in your cron tab


* * * * * php /var/www/html/laravelTarun/artisan schedule:run 1>> 

/dev/null 2>&1


Here /var/www/html/laravelTarun/ is your path to the  project


4.3 Now Add the below line to your Kernel.php file


$schedule->command('log:demo')->everyMinute();


This will run the log:demo command every minute and store the 

output in the log file.


That's it open laravel.log file inside /storage/logs/ directory 

wait for 1 minute and you will see the log


my file output after 7 minute:



[2016-07-24 09:08:57] local.INFO: Showing user profile for user

[2016-07-24 09:09:11] local.INFO: Showing user profile for user

[2016-07-24 09:18:02] local.INFO: Showing user profile for user

[2016-07-24 09:19:01] local.INFO: Showing user profile for user

[2016-07-24 09:20:01] local.INFO: Showing user profile for user

[2016-07-24 09:21:01] local.INFO: Showing user profile for user

[2016-07-24 09:22:01] local.INFO: Showing user profile for user


That's it your have learned how the schedule task in laravel.


Saturday, 23 July 2016

CRON TAB SETUP IN THE UBUNTU 15.10 LTS


Cron is a daemon that executes scheduled commands. 


If you want to do some task repetitively, you can add your task 

in the crontab, it will handle all for you.



Crontab is the program used to install, deinstall or list the tables 

used to drive the cron daemon in Vixie Cron. Each user can have 

their own crontab, and though these are files in 

/var/spool/cron/crontabs, they are not intended to be edited directly.

Each user root or other has their own crontab, and commands in 

any given crontab will be executed as the user who is the owner of 

the crontab.



Crontab Commands


crontab -e For creating new cron file


crontab -l list the crontab files


crontab -r remove crontab files



cron files options:

m     -    minute 0-59

h      -    hour 0-11

dom -    day of month 1-31

mon -    month 1-12 OR Jan-Dec

dow -    day of week 0-6 OR Sun-Sat

command - you command (ls -la or and script name ./foo)

* means irrespective of(For example I do not want specify the cron 


to run without taking consideration “dow” I will write as * in that 


place like this 41 19 23 7 * ls -la)




Example for crontab.


I want to run the command


ls -la


and output should be store in the file cronLog file which is located 


in the /var/log directory.I will write in the cron file as


ls -la >>/var/log/cronLog



It will list all your file and store the output in cronLog file


Cron searches its spool(jobs to execute) area in 


/var/spool/cron/crontabs directory for crontab files.


We will execute the above example with step by step.


Step1: Adding Command in the Cron


cd ~


crontab -e



a file will be opened with content as:


# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command




Here you need to only focus only on the last line that' it

# m h dom mon dow command


m – minute 0-59


h – hour 0-11


dom- day of month 1-31


mon- month 1-12 OR Jan-Dec


dow- day of week 0-6 OR Sun-Sat


command – you command ls -la or and script name ./foo




When you will save the file, you can see that a file will be created 

as in /var/spool/cron/crontabs 


-rw------- 1 root crontab 1128 Jul 23 19:39 root



in the /var/spool/cron/crontabs directory, where cron daemon

will read it and execute it.


Step2: Add the following line at the end of file, like this



# m h dom mon dow command


41 19 23 7 * ls -la >>/var/log/cronLog



Here * means irrespective of that thing.


What it will do, it list all the file in the current directory at 

Jul 23rd,19:41, irrespective of the day of week and store that in 


/var/log/cronLog



That's it you have made your first cron.