Skip to content

Instantly share code, notes, and snippets.

@byronwade
Created August 18, 2013 07:01
Show Gist options
  • Save byronwade/6260300 to your computer and use it in GitHub Desktop.
Save byronwade/6260300 to your computer and use it in GitHub Desktop.
can one of you point me in the right direction, ok so i want to make this script upload more then one file and have more checks also im trying to figure out hoe to sort out category's for each of the photos so that when i have to go threw the photos later to make sure there are no inappropriate things uploaded how would i do this to make it easi…
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Thorbis | Pictures</title>
<link rel="shortcut icon" href="bin/favicon.ico" />
<link href="http://fonts.googleapis.com/css?family=Open+Sans:300,600,700" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="bin/lightbox/lightbox.css" />
<link href="http://fonts.googleapis.com/css?family=Open+Sans:300,600,700" rel="stylesheet" />
<script src="js/jquery.min.js"></script>
<script src="js/config.js"></script>
<script src="js/skel.min.js"></script>
<noscript>
<link rel="stylesheet" href="css/skel-noscript.css" />
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/style-desktop.css" />
</noscript>
<script src="bin/lightbox/jquery-1.7.2.min.js"></script>
<script src="bin/lightbox/lightbox.js"></script>
<!-- Nav -->
<nav id="nav">
<ul>
<li><a href="#work">Top</a></li>
<li><a href="http://www.thorbis.com/index.html#home">Home</a></li>
<li><a href="#pictures">Pictures</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
<div class="wrapper wrapper-style2">
<article id="work">
<header>
<span><strong>You can upload funny pictures only! All others will be deleted!</strong></span></br>
<span>All the pictures sort alphabetically and some images overlay others if they have the same name so make yours unique!</span></br>
<span> You can upload <strong>ONLY</strong> ".png", ".PNG", ".jpg", ".JPG", ".jpeg", ".JPEG", ".gif", ".GIF" </span>
</header>
<div style="margin:1em auto;">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
<input type="file" name="fileup"/><input type="submit" name='submit' value="Upload" />
</form>
</div>
</head>
<?php
$uploadpath = 'galleries/'; // directory to store the uploaded files
$max_size = 5000; // maximum file size, in KiloBytes
$alwidth = 1200; // maximum allowed width, in pixels
$alheight = 1000; // maximum allowed height, in pixels
$allowtype = array('bmp', 'gif', 'jpg', 'jpe', 'png'); // allowed extensions
if(isset($_FILES['fileup']) && strlen($_FILES['fileup']['name']) > 1) {
$uploadpath = $uploadpath . basename( $_FILES['fileup']['name']); // gets the file name
$sepext = explode('.', strtolower($_FILES['fileup']['name']));
$type = end($sepext); // gets extension
list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']); // gets image width and height
$err = ''; // to store the errors
// Checks if the file has allowed type, size, width and height (for images)
if(!in_array($type, $allowtype)) $err .= 'The file: <b>'. $_FILES['fileup']['name']. '</b> not has the allowed extension type.';
if($_FILES['fileup']['size'] > $max_size*1000) $err .= '<br/>Maximum file size must be: '. $max_size. ' KB.';
if(isset($width) && isset($height) && ($width >= $alwidth || $height >= $alheight)) $err .= '<br/>The maximum Width x Height must be: '. $alwidth. ' x '. $alheight;
// If no errors, upload the image, else, output the errors
if($err == '') {
if(move_uploaded_file($_FILES['fileup']['tmp_name'], $uploadpath)) {
echo 'File: <b>'. basename( $_FILES['fileup']['name']). '</b> successfully uploaded:';
echo '<br />Size: <b>'. number_format($_FILES['fileup']['size']/1024, 3, '.', '') .'</b> KB';
if(isset($width) && isset($height))
echo "</br><img height='70px' width='70px' src='http://www.thorbis.com/pictures/$uploadpath'></img>";
}
else echo '<b>Unable to upload the file.</b>';
}
else echo $err;
}
?>
<footer>
<a href="#pictures" class="button button-big">Pictures</a>
</footer>
</article>
</div>
<div class="wrapper wrapper-style6">
<article id="pictures">
<header>
<h2>Great Pictures</h2>
</header>
<div class="container">
<?php
$filetypes = array(".png", ".PNG", ".jpg", ".JPG", ".jpeg", ".JPEG", ".gif", ".GIF");
$basedir = 'galleries/';
$currentdir = '';
if(isset($_GET['f']) ? $_GET['f'] : '')
{
$currentdir = '/'.$_GET['f'].'/';
}
function scandirSorted($path)
{
$sortedData = array();
$data1 = array();
$data2 = array();
foreach(scandir($path) as $file)
{
if(!strstr($path, '..'))
{
if(is_file($path.$file))
{
array_push($data2, $file);
}
else
{
array_push($data1, $file);
}
}
}
$sortedData = array_merge($data1, $data2);
return $sortedData;
}
function strpos_arr($haystack, $needle)
{
if(!is_array($needle))
{
$needle = array($needle);
}
foreach($needle as $what)
{
if(($pos = strpos($haystack, $what)) !== false)
{
return $pos;
}
}
return false;
}
function addThumb($filename)
{
$filename = array_reverse(explode('.', $filename));
$filename[0] = 'smpgthumb.'.$filename[0];
$filename = implode('.', array_reverse($filename));
return $filename;
}
if(is_dir($basedir.$currentdir))
{
$folder = array_diff(scandirSorted($basedir.$currentdir), array('..', '.', 'Thumbs.db', 'thumbs.db', '.DS_Store'));
}
$navigation = explode('/', $currentdir);
$navigation_elements = count($navigation);
if(isset($_GET['f']))
{
echo('<div id="navigation"><a href="./">Home</a>');
}
foreach($navigation as $element)
{
if($element)
{
echo(' / <a href="?f='.str_replace('//', '/', str_replace(' ', '%20', substr($currentdir, 0, strpos($currentdir, $element)+strlen($element)))).'">'.$element.'</a>');
}
}
if(isset($_GET['f']))
{
echo('</div>');
}
echo('<div id="content">');
foreach($folder as $item)
{
if(!strstr(isset($_GET['f']), '..'))
{
if(!strstr($item, 'smpgthumb'))
{
if(strpos_arr($item, $filetypes))
{
if(file_exists($basedir.$currentdir.'/'.addThumb($item)))
{
echo('<a href="'.str_replace('//', '/', str_replace(' ', '%20', $basedir.$currentdir.'/'.$item)).'" rel="friend"><img src="'.str_replace('//', '/', str_replace(' ', '%20', $basedir.$currentdir.'/'.addThumb($item))).'" class="img" alt="" /></a> ');
}
else
{
echo('<a href="'.str_replace('//', '/', str_replace(' ', '%20', $basedir.$currentdir.'/'.$item)).'" rel="friend"><img src="bin/thumb.php?file='.str_replace('//', '/', str_replace(' ', '%20', $basedir.$currentdir.'/'.$item)).'" class="img" alt="" /></a> ');
}
}
else
{
echo('<a href="?f='.str_replace('//', '/', str_replace(' ', '%20', $currentdir.'/'.$item)).'">'.$item.'</a><br>');
}
}
}
}
echo('</div>');
?>
</div>
</body>
<footer>
<a href="#work" class="button button-big">Back To The Top</a>
</footer>
</article>
</div>
<!-- Contact -->
<div class="wrapper wrapper-style4">
<article id="contact">
<header>
<h2>Want to hire me? Get in touch!</h2>
<span>I do quality work and would love to work for you!.</span>
</header>
<div>
<div class="row">
<div class="12u">
<div id="errors"></div>
<form method='post' enctype="multipart/form-data" action='mailform.php' id='contact-form'>
<div>
<div class="row half">
<div class="6u">
<input type="text" name="name" min-length='' id="name" placeholder="Name" />
</div>
<div class="6u">
<input type="text" name="email" id="email" placeholder="Email" />
</div>
</div>
<div class="row half">
<div class="12u">
<input type="text" name="subject" id="subject" placeholder="Subject" />
</div>
</div>
<div class="row half">
<div class="12u">
<textarea name="message" id="message" placeholder="Message"></textarea>
</div>
</div>
<div class="row half">
<div class="12u">
<p><label for="file">Upload a file to help me get an idea of what you want .zip are recomended</label><input type="file" name="file" id="file"></p>
<div class="row">
</div>
</div>
<div class="12u">
<a href="#" type="submit" name="submit" id="submit" value="send" class="button form-button-submit">Send Message</a>
<a href="#" class="button button-alt form-button-reset">Clear Form</a>
</div>
</div>
</div>
</form>
<script>
$('#contact-form').submit(function(e) {
var valid = true;
$('input[type=text],textarea').each(function() {
if (!$(this).val()) {
valid = false;
$(this).addClass('invalid');
}
if ($(this).is('#email') && $(this).val().indexOf('@') === false) {
valid = false;
$(this).addClass('invalid');
}
});
if (!valid) {
$('#botSmallPic1').click(function(){$.smallBox({title:'New Notifacation!',content:'I Hope Your All Doing Well ',timeout:10000,color:'green',img:'img/pic1.png'})});
$('#bot').click(function(){$.smallBox({title:'hi!',content:'I Hope Your All Doing Well ',timeout:10000,color:'blue',img:'img/pic1.png'})});
$("#Big").click(function(){$.bigBox({title:"no",content:"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco. Lorem ipsum dolor sit amet.",color:"lightblue",img:"img/cloud.png",number:"5"})});
$("#BigBoxCall1").click(function(){$.bigBox({title:"Big Information box",content:"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco. Lorem ipsum dolor sit amet.",color:"breen",img:"img/cloud.png",number:"5"})});
$("#botMessage1").ready(function(){$.MetroMessageBox({title:"Wrong input The form wasent filled out correctly",content:"Please try again input again with propper inputs",NormalButton:"blue",ActiveButton:"lightblue"})});
return false;
}
});
</script>
</div>
</div>
<div class="row row-special">
<div class="12u">
<h3>Find me on ...</h3>
<ul class="social">
<li class="twitter"><a href="http://twitter.com/thorbis" class="icon icon-twitter"><span>Twitter</span></a></li>
<li class="facebook"><a href="https://www.facebook.com/ThorbisInc" class="icon icon-facebook"><span>Facebook</span></a></li>
<li class="linkedin"><a href="http://www.linkedin.com/profile/view?id=226237754&goback=%2Enmp_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1&trk=spm_pic" class="icon icon-linkedin"><span>LinkedIn</span></a></li>
<li class="tumblr"><a href="http://thorbis.tumblr.com/" class="icon icon-tumblr"><span>Tumblr</span></a></li>
<li class="googleplus"><a href="https://plus.google.com/u/0/113626141520121345204/posts?partnerid=gplp0" class="icon icon-google-plus"><span>Google+</span></a></li>
<li class="youtube"><a href="https://www.youtube.com/user/byronwade10" class="icon icon-youtube"><span>YouTube</span></a></li>
<li class="flickr"><a href="http://www.flickr.com/people/98912309@N04/" class="icon icon-flickr"><span>Flickr</span></a></li>
<li class="vimeo"><a href="https://vimeo.com/user19548393" class="icon icon-vimeo"><span>Vimeo</span></a></li>
<!--
<li class="github"><a href="http://github.com/" class="icon icon-github"><span>Github</span></a></li>
<li class="dribbble"><a href="http://dribbble.com/n33" class="icon icon-dribbble"><span>Dribbble</span></a></li>
<li class="rss"><a href="#" class="icon icon-rss"><span>RSS</span></a></li>
<li class="instagram"><a href="#" class="icon icon-instagram"><span>Instagram</span></a></li>
<li class="foursquare"><a href="#" class="icon icon-foursquare"><span>Foursquare</span></a></li>
<li class="skype"><a href="#" class="icon icon-skype"><span>Skype</span></a></li>
<li class="soundcloud"><a href="#" class="icon icon-soundcloud"><span>Soundcloud</span></a></li>
<li class="blogger"><a href="#" class="icon icon-blogger"><span>Blogger</span></a></li>
-->
</ul>
</div>
</div>
</div>
<footer>
<footer>
<p id="copyright">
&copy; 2012 Thorbis Inc. | Design: <a href="http://html5up.net/">HTML5 UP</a>
</p>
</footer>
</footer>
</article>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment