-1

I need PHP code to download file from one server to another. It's defined by variable $HasPrevod. That's the file which I need to download. Also there's simple form where I put link and the output is that variable $HasPrevod, so I had to put it in a href to get link easily to download.

<a href="$HasPrevod">Download</a>. and download it manually and upload via Filezilla on my server. Is there solution which will download content from that variable and put it on my server in some folder. I tried with cURL but nothing happened because I'm newbie and I've made mistake for shure, and I don't know much about PHP and cURL.

So it should be something like this $HasPrevod file download -> my server / folder, and echo file name.

$prevod = $_POST['prevod'];
$url = file_get_contents("$prevod");
$PrevodLink = preg_match('!http://[a-z0-9\S\ \-\_\.\[\]\[\]\/]+\.(?:srt)!Ui', $url, $match1);
$HasPrevod = $match1['0'];

<form action="prevod.php" method="post"> 
<input name="prevod" type="text"/> 
<input type="submit" value="Search"/>
</form>

Thats the code I'm using to put link and get path to the file which is located on another website not my own, then I have to download manually and upload on my server via Filezilla.

<a href= "<?php echo $HasPrevod; ?>">Download</a>




curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec ($ch);
curl_close ($ch);
$destination = "prevodi/". $HasPrevod;
$file = fopen($destination, "w+");
fputs($file, $data);
fclose($file);

2 Answers2

0
file_put_contents('path/to/file.ext', file_get_contents($HasPrevod));
Steve
  • 20,703
  • 5
  • 41
  • 67
  • I've tried allready, and all I get it's blank file created on server. – user3739435 Jun 18 '14 at 09:50
  • @user3739435 OK, well you need to do some debugging then, turn on error reporting and see what `var_dump(file_get_contents($HasPrevod);` gives you – Steve Jun 18 '14 at 09:52
0

If you have enough permission, try with exec('wget http://www.example.com/myFile.zip');

If not, try with file_put_contents() method. At last if that now works, try to var_dump() some states of code to debug it.

Dusan
  • 276
  • 1
  • 16