Hello guys....this is my first thread
I started with php last week just for fun...and found php as one of the easiest lang. to learn and much more versatile ..
Now then;i wrote a code in php to extract all links from webpage and save them(basically to view the source code of html files).
Firstly i saved this webpage in a txt file using copy function which worked
perfectly well for wepages with extension(.html or .htm)
copy("$_POST['url]","sourcecode.txt");
Then i extracted the links from the webpage ,saved them in text file and
using "<input type"checkbox"...........selected the links (mainly html or txt)
which i again tried to save using copy function ...but here lies the problem i m not able to make it work .
Source code:
<?php
/*assume $_POST['links'] contains a single link
http://www.anysite.com/dummy/source.html*/
//echo "<br>hello";
$v=$_POST['links'];
//-------Function to extract the file name from complete link---------
//For eg:i/p=http://www.anysite.com/dummy/source.html
// o/p=source.html
function filename($f)
{
$pos=strripos($f,"/");
$v=substr($f,$pos+1);
return $v;
}
foreach ($v as $link)//right now assuming only one link is present
{
copy($link,filename($link));//doesn't work
/*copy("http://www.anysite.com/dummy/source.html","source.html"); this one works*/
echo "<br>Source : $link";
echo "<br>Destination :". filename($link);
}
?>
Output:
Source : http://www.anysite.com/dummy/source.html
Destination :source.html
with no file being copied...
i tries using fopen() to open links but doesn't seem to work with http://
Also,kindly..suggest a better a way to download content from web.(mainly
html and pdf files) using php.
I am using apache 2.2.4 PHP 5.2.3