Indentation - php-cs-fixer
This commit is contained in:
parent
43f4052d86
commit
1327eba46a
1 changed files with 35 additions and 33 deletions
68
index.php
68
index.php
|
|
@ -1,51 +1,53 @@
|
||||||
<?php
|
<?php
|
||||||
if(!empty($_GET['url'])) {
|
if (!empty($_GET['url'])) {
|
||||||
$url = $_GET['url'];
|
$url = $_GET['url'];
|
||||||
|
|
||||||
if(strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) {
|
if (strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) {
|
||||||
$url = 'http://'.$url;
|
$url = 'http://'.$url;
|
||||||
}
|
}
|
||||||
|
|
||||||
$urlhash = sha1($url);
|
$urlhash = sha1($url);
|
||||||
|
|
||||||
$hashfolder = substr($urlhash, 0, 2);
|
$hashfolder = substr($urlhash, 0, 2);
|
||||||
$hashfile = substr($urlhash, 2);
|
$hashfile = substr($urlhash, 2);
|
||||||
|
|
||||||
$hashfolderpath = './db/' . $hashfolder;
|
$hashfolderpath = './db/'.$hashfolder;
|
||||||
$hashfilepath = $hashfolderpath . '/' . $hashfile;
|
$hashfilepath = $hashfolderpath.'/'.$hashfile;
|
||||||
|
|
||||||
mkdir($hashfolderpath, 0700, true);
|
mkdir($hashfolderpath, 0700, true);
|
||||||
|
|
||||||
file_put_contents($hashfilepath, $url);
|
file_put_contents($hashfilepath, $url);
|
||||||
$content = '<a href="./?'.$urlhash.'">./?'.$urlhash.'</a><br />
|
$content = '<a href="./?'.$urlhash.'">./?'.$urlhash.'</a><br />
|
||||||
As long as there is not collision, you can shorten it down to 3 characters.';
|
As long as there is not collision, you can shorten it down to 3 characters.';
|
||||||
} else if(!empty($_GET)) {
|
} elseif (!empty($_GET)) {
|
||||||
$urlhash = key($_GET);
|
$urlhash = key($_GET);
|
||||||
|
|
||||||
$hashfolder = substr($urlhash, 0, 2);
|
$hashfolder = substr($urlhash, 0, 2);
|
||||||
$hashfile = substr($urlhash, 2);
|
$hashfile = substr($urlhash, 2);
|
||||||
|
|
||||||
$hashfolderpath = './db/' . $hashfolder;
|
$hashfolderpath = './db/'.$hashfolder;
|
||||||
$hashfilepath = $hashfolderpath . '/' . $hashfile;
|
$hashfilepath = $hashfolderpath.'/'.$hashfile;
|
||||||
|
|
||||||
$findfiles = glob($hashfilepath . '*');
|
$findfiles = glob($hashfilepath.'*');
|
||||||
|
|
||||||
if(empty($findfiles)) {
|
if (empty($findfiles)) {
|
||||||
$content = 'No files.';
|
$content = 'No files.';
|
||||||
return 1;
|
|
||||||
} else if (count($findfiles) > 1) {
|
|
||||||
foreach($findfiles as $file) {
|
|
||||||
$file = str_replace('/', '', substr($file, 5));
|
|
||||||
$content = '<a href="./?'.$file.'">./?'.$file.'</a><br />';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$fullfilepath = current($findfiles);
|
return 1;
|
||||||
|
} elseif (count($findfiles) > 1) {
|
||||||
|
foreach ($findfiles as $file) {
|
||||||
|
$file = str_replace('/', '', substr($file, 5));
|
||||||
|
$content = '<a href="./?'.$file.'">./?'.$file.'</a><br />';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
header('Location:' . file_get_contents($fullfilepath));
|
$fullfilepath = current($findfiles);
|
||||||
return 0;
|
|
||||||
|
header('Location:'.file_get_contents($fullfilepath));
|
||||||
|
|
||||||
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
$content = '<form method="get">
|
$content = '<form method="get">
|
||||||
Enter your URL: <input type="text" name="url"><input type="submit" value="Submit">
|
Enter your URL: <input type="text" name="url"><input type="submit" value="Submit">
|
||||||
</form>';
|
</form>';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue