Skip to content

Instantly share code, notes, and snippets.

@tt024
Last active May 6, 2020 19:48
Show Gist options
  • Save tt024/fc2cfcb736a60108c11d6a3b39392f6e to your computer and use it in GitHub Desktop.
Save tt024/fc2cfcb736a60108c11d6a3b39392f6e to your computer and use it in GitHub Desktop.
Image hoster without SQL
<?php
$max_size = 512000;)
$repertory = 'uploads/';
if (isset($_FILES['file']))
{
// verify file type
if ($_FILES['file']['type'] != 'image/png' && $_FILES['file']['type'] != 'image/jpeg' && $_FILES['file']['type'] != 'image/jpg' && $_FILES['file']['type'] != 'image/gif' && $_FILES['file']['type'] != 'image/bmp' && $_FILES['file']['type'] != 'image/jpg' && $_FILES['file']['type'] != 'image/png' && $_FILES['file']['type'] != 'image/ico')
{
$error = 'Only *.jpeg, *.bmp, *.jpg, *.png, *.ico *.gif ou *.png .';
}
// max size of file
elseif ($_FILES['file']['size'] > $max_size)
{
$error = 'Max ' . $max_size/1024 . 'Ko.';
}
// /uploads/ exist ?
elseif (!file_exists($repertory))
{
$error = 'error, the upload file doesn't exist';
}
// error
if(isset($error))
{
echo '' . $error . '<br><a href="javascript:history.back(1)">Retour</a>';
}
else
{
// the desired file
if ($_FILES['file']['type'] == 'image/jpeg') { $extention = '.jpeg'; }
if ($_FILES['file']['type'] == 'image/jpeg') { $extention = '.jpg'; }
if ($_FILES['file']['type'] == 'image/png') { $extention = '.png'; }
if ($_FILES['file']['type'] == 'image/gif') { $extention = '.gif'; }
$filename = time().$extention;
// upload
if (move_uploaded_file($_FILES['file']['tmp_name'], $repertory.$filename))
{
$url = 'website.com/'.$repertory.''.$filename.'';
echo 'Your pictures was uploaded!<br>Link: <br />
<br/>
<img src="uploads/'.$filename.'" width="120px" height="120px" border="2px" />
<br/>
<b>BBcode img</b> = <input type="text" value="[img]' . $url . '[/img]" /><br />
<br />
<b>BBcode url</b> = <input type="text" value="[url]' . $url . '[/url]" /><br />
<br />
<b>HTML direct </b> <input type="text" value="'.$url.'" />
';
}
else
{
echo 'Error! Image not uploaded!';
}
}
}
else
{
?>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_size; ?>">
<input type="file" name="file">
<input type="submit" value="Submit">
</form>
<?php
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment