-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownloadableFile.php
More file actions
59 lines (49 loc) · 1.94 KB
/
DownloadableFile.php
File metadata and controls
59 lines (49 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
abstract class DownloadableFile {
protected $dir = "download";
protected $filename;
protected $ext;
protected function __construct($filename="", $ext){
if($this->filename==""){
$this->createFilename();
} else {
$this->filename = $filename;
}
$this->ext = $ext;
}
public abstract function create($data);
public function createFilename($length = 8, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
{
$pieces = [];
$max = mb_strlen($keyspace, '8bit') - 1;
for ($i = 0; $i < $length; ++$i) {
$pieces []= $keyspace[random_int(0, $max)];
}
$this->filename = implode('', $pieces);
}
public function getDirFile($ext=""){
$ext = ($ext=="")?$this->ext:$ext;
return $this->dir."/".$this->filename.".".$ext;
}
public function getFilename(){
return $this->filename;
}
public function removeFile($ext=""){
unlink($this->getDirFile($ext));
}
public function send($url, $fields){
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields);
//So that curl_exec returns the contents of the cURL; rather than echoing it
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec($ch);
return $result;
}
}