Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

PHP – File Download

Posted on March 16, 2016 By David Kittell

When WGET isn’t available PHP comes to the rescue. In this example $path file name can be different than the $url file name or the same, if it is different it will be saved with the file name in $path

set_time_limit(0); //Unlimited max execution time
 
$path = 'filetodownload.txt';
$url = 'http://domain.com/currentfilename.txt';
$newfname = $path;
echo 'Starting Download!<br>';
$file = fopen ($url, "rb");
if($file) {
	$newf = fopen ($newfname, "wb");
	if($newf)
		while(!feof($file)) {
			fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
			echo '1 MB File Chunk Written!<br>';
		}
}
if($file) {
	fclose($file);
}
if($newf) {
	fclose($newf);
}
echo 'Finished!';
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code PHP

Post navigation

Previous post
Next post

Related Posts

Mac OSX Terminal – Change/Set DNS

Posted on May 27, 2016June 4, 2020

This may need to change depending on your network interface Manual Process # Only friendly names networksetup -listallnetworkservices # Useful information networksetup -listallhardwareports Running the above will display something like this An asterisk (*) denotes that a network service is disabled. Ethernet FireWire Wi-Fi Bluetooth PAN Thunderbolt Bridge # Optional…

Read More

ASPX Page Control Enable / Disable

Posted on March 12, 2014October 26, 2015

In some cases you need to disable controls on a page, this will help you disable various types of controls. protected void ControlsEnabler (Control parent, bool State) { foreach (Control c in parent.Controls) { if (c is TextBox) { ((TextBox)(c)).Enabled = State; } if (c is CheckBox) { ((CheckBox)(c)).Enabled =…

Read More

Calculate Age Function

Posted on February 25, 2013October 26, 2015

Two variations of the function but the purpose is to determine the difference in dates and display the result in one column. IF OBJECT_ID(N’dbo.fnAge’) IS NOT NULL DROP FUNCTION dbo.fnAge GO CREATE FUNCTION [dbo].[fnAge] ( @dayOfBirth DATETIME ,@today DATETIME ) RETURNS VARCHAR(100) AS BEGIN DECLARE @thisYearBirthDay DATETIME DECLARE @years INT…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes