Skip to content

Commit eefbe6b

Browse files
authored
Add files via upload
1 parent 57c54c4 commit eefbe6b

File tree

3 files changed

+241
-0
lines changed

3 files changed

+241
-0
lines changed

index.html

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css">
8+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
9+
<link rel="stylesheet" href="css/theme.css" type="text/css">
10+
<link rel="stylesheet" href="theme.css" type="text/css">
11+
<title>Split and Merge Files</title>
12+
<meta name="keywords" content="Split,Merge">
13+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
14+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
15+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
16+
17+
<body class="">
18+
<div class="py-3">
19+
<div class="container">
20+
<div class="row">
21+
<div class="col-md-12">
22+
<h1 class="text-center display-2 filter-fade-in">Parts Download</h1>
23+
</div>
24+
</div>
25+
</div>
26+
</div>
27+
<div class="py-3 bg-gradient">
28+
<div class="container">
29+
<div class="row">
30+
<div class="col-md-4"></div>
31+
<div class="col-md-4">
32+
<form class="text-center" action="" method="POST">
33+
<div class="form-group text-left"> <label><b>Dowload Link :</b></label>
34+
<input type="text" class="form-control" placeholder="Enter Link of file" id="dfile" name="dfile" required="required"> </div>
35+
<div class="form-group text-left"> <label><b>Save to :</b></label>
36+
<input type="text" class="form-control" placeholder="Out put file path" id="sfile" name="sfile" required="required"> </div>
37+
<div class="form-group text-left"><label for="exampleInputEmail1"><b>Part Size :</b></label>
38+
<input type="number" class="form-control" id="psize" placeholder="Size if each part in (Kb)" name="psize">
39+
</div>
40+
<button type="button" class="btn text-center btn-success" Onclick="checkfexist();">Submit</button>
41+
</form>
42+
</div>
43+
<div class="col-md-4"></div>
44+
</div>
45+
</div>
46+
</div>
47+
<div class="">
48+
<div class="container">
49+
<div class="row">
50+
<div class="col-sm-12 col-sm-offset-5 col-md-8 offset-md-2">
51+
<div class="alert alert-success text-center my-3 p-3" style="display:none" id="salert">The file has been successfully downloaded part by part.</div>
52+
</div>
53+
</div>
54+
</div>
55+
</div>
56+
<div class="py-1 bg-gradient">
57+
<form class="text-center" method="POST" target="myIframe">
58+
<div class="container">
59+
<div class="row">
60+
<div class="col-md-12">
61+
<div class="input-group text-center bg-gradient">
62+
<input type="text" class="form-control form-control-lg text-left" placeholder="http://" id="linkurl">
63+
<div class="input-group-append">
64+
<button class="btn btn-success px-4" type="button" Onclick="setURL();">Visit</button>
65+
</div>
66+
</div>
67+
</div>
68+
</div>
69+
</div>
70+
</form>
71+
<div class="container">
72+
<div class="row">
73+
<div class="col-md-12">
74+
<div class="input-group text-center bg-gradient">
75+
<iframe height="300px" width="100%" src="" name="myIframe" id="myIframe"> Your browser doesn't load this iframe.</iframe>
76+
</div>
77+
</div>
78+
</div>
79+
</div>
80+
</div>
81+
82+
<script>
83+
$(function() {
84+
$( "#progressbar" ).progressbar({
85+
aria-valuenow: 90
86+
});
87+
});
88+
</script>
89+
<script>
90+
function stratdown() {
91+
var dfilename = $('#dfile').val();
92+
var sfilename = $('#sfile').val();
93+
var partsizevalue = $('#psize').val();
94+
$.ajax({
95+
type: "POST",
96+
url: 'trigger.php',
97+
data:{dfile: dfilename, sfile: sfilename, psize: partsizevalue},
98+
success:function(result) {
99+
alert("The file has been successfully downloaded");
100+
$("#salert").show();
101+
setTimeout(function() { $("#salert").hide(); }, 5000);
102+
103+
}
104+
105+
});
106+
//alert("working");
107+
}
108+
function checkfexist() {
109+
var sfilename = $('#sfile').val();
110+
if (sfilename !='') {
111+
$.ajax({
112+
url: sfilename,
113+
type: 'GET',
114+
error: function()
115+
{
116+
stratdown();
117+
},
118+
success: function()
119+
{
120+
var site = prompt("The File already exists rename bellow", "");
121+
if (site != '') {
122+
document.getElementById("sfile").value = site;
123+
}else {
124+
alert("File name cannot be empty");
125+
}
126+
}
127+
});
128+
}else{
129+
alert ('File name cannot be empty');}
130+
}
131+
function setURL(){
132+
document.getElementById('myIframe').src = "";
133+
setTimeout(function () {
134+
document.getElementById('myIframe').src = document.getElementById('linkurl').value;
135+
}, 0);
136+
}
137+
</script>
138+
</body>
139+
140+
</html>

partdown.php

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copy remote file over HTTP one small chunk at a time.
4+
* @param $infile The full URL to the remote file
5+
* @param $outfile The path where to save the file
6+
*/
7+
class DownInParts
8+
{
9+
public function copyfile_chunked($infile, $outfile, $partsize)
10+
{
11+
$chunksize = $partsize * 1024; // 10 Megs
12+
13+
/**
14+
* parse_url breaks a part a URL into it's parts, i.e. host, path,
15+
* query string, etc.
16+
*/
17+
$parts = parse_url($infile);
18+
$i_handle = fsockopen($parts['host'], 80, $errstr, $errcode, 5);
19+
$o_handle = fopen($outfile, 'wb');
20+
21+
if ($i_handle == false || $o_handle == false) {
22+
return false;
23+
}
24+
25+
if (!empty($parts['query'])) {
26+
$parts['path'] .= '?' . $parts['query'];
27+
}
28+
29+
/**
30+
* Send the request to the server for the file
31+
*/
32+
$request = "GET {$parts['path']} HTTP/1.1\r\n";
33+
$request .= "Host: {$parts['host']}\r\n";
34+
$request .= "User-Agent: Mozilla/5.0\r\n";
35+
$request .= "Keep-Alive: 115\r\n";
36+
$request .= "Connection: keep-alive\r\n\r\n";
37+
fwrite($i_handle, $request);
38+
39+
/**
40+
* Now read the headers from the remote server. We'll need
41+
* to get the content length.
42+
*/
43+
$headers = array();
44+
while(!feof($i_handle)) {
45+
$line = fgets($i_handle);
46+
if ($line == "\r\n") break;
47+
$headers[] = $line;
48+
}
49+
50+
/**
51+
* Look for the Content-Length header, and get the size
52+
* of the remote file.
53+
*/
54+
$length = 0;
55+
foreach($headers as $header) {
56+
if (stripos($header, 'Content-Length:') === 0) {
57+
$length = (int)str_replace('Content-Length: ', '', $header);
58+
break;
59+
}
60+
}
61+
62+
/**
63+
* Start reading in the remote file, and writing it to the
64+
* local file one chunk at a time.
65+
*/
66+
$cnt = 0;
67+
while(!feof($i_handle)) {
68+
$buf = '';
69+
$buf = fread($i_handle, $chunksize);
70+
$bytes = fwrite($o_handle, $buf);
71+
if ($bytes == false) {
72+
return false;
73+
}
74+
$cnt += $bytes;
75+
76+
/**
77+
* We're done reading when we've reached the content length
78+
*/
79+
if ($cnt >= $length) break;
80+
}
81+
82+
fclose($i_handle);
83+
fclose($o_handle);
84+
return $cnt;
85+
}
86+
}
87+
?>

trigger.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
set_time_limit (0);
3+
require 'partdown.php';
4+
$infile = $_POST["dfile"];
5+
$outfile = $_POST["sfile"];
6+
$partsize = $_POST["psize"];
7+
if (file_exists($outfile)) {
8+
echo "confirm(The file ( $outfile ) already exist. Cick 'confirm' to overwrite) ";
9+
10+
}
11+
12+
DownInParts::copyfile_chunked($infile, $outfile, $partsize);
13+
14+
?>

0 commit comments

Comments
 (0)