Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //uncomment this when u have imagecfg.php
- // include('imagecfg.php');
- $siteURL = "http://localhost";
- $uploadDir = "images";
- if ($_POST['localUpload']) {
- $name = $_FILES['imagefile']['name']; //file name
- $type = $_FILES['imagefile']['type']; // type of file
- $size = $_FILES['imagefile']['size']; //size of the mage in bytes
- $tmp_name = $_FILES['imagefile']['tmp_name']; //temp file name and location
- $ext = substr($name, strrpos($name, '.')); //grab file extension
- // Requirements
- $dimension = getimagesize($tmp_name);
- $width = $dimension[0];
- $height = $dimension[1];
- // get the extension of the file in a lower case format
- $ext = strtolower($ext);
- if (array($type, $allowed) && ($maxfileSize) && ( $width < $maxWidth && $height < $maxHeight )) {
- $name = strtotime(gmdate("M d Y H:i:s", time())).''.$ext; //we will give an unique name, for example the time in unix time format
- move_uploaded_file($tmp_name, $uploadDir.'/'.$name); // upload the image, eventually i want to force the image on server to use my preferred file type
- echo "
- <div align='center'>You've just successfully uploaded $name with the following specifications $size bytes and $width x $height px</div>
- <div align='center'><a href='$uploadDir/$name'><img src='$uploadDir/$name' alt='Uploaded image'></a></div>
- <div align='center'>Direct Image Links</div>
- <p align='center'>URL: <input tabindex='1' value='$siteURL/$uploadDir/$name' onclick='this.focus();this.select();' /></p>
- <p align='center'>HTML: <input tabindex='2' value='<a href="$siteURL/$uploadDir/$name"><img src="$siteURL/$uploadDir/$name" border="0"></a>' onclick='this.focus();this.select();' /></p>";
- }
- else
- echo "<p>You have submitted an invalid extension/larger file size than we accept or the dimensions are too big.</p>";
- } // < attempting a local upload and all checks.
- elseif (isset($_POST['remoteUpload'])) {
- $urls = explode("\n", $_POST['remoteimage']);
- $imgarray = array();
- foreach ($urls as $url)
- {
- $url = trim($url);
- $imgname = strtotime(gmdate("M d Y H:i:s", time())) . '-' . basename($url);
- $localimg = $uploadDir .'/'. $imgname;
- $img = file_get_contents($url);
- file_put_contents($localimg, $img);
- $url = $baseurl . $imgname;
- echo "<div align='center'>You've just successfully uploaded $imgname.</div>
- <div align='center'><a href='$localimg'><img src='$localimg' alt='Uploaded image'></a></div>
- <div align='center'>Direct Image Links</div>
- <p align='center'>URL: <input tabindex='1' value='$siteURL/$localimg' onclick='this.focus();this.select();' size='65' /></p>
- <p align='center'>HTML: <input tabindex='2' value='".htmlspecialchars_decode("<a href=\"$siteURL/$localimg\"><img src=\"$localimg\" border=\"0\"></a>")."' onclick='this.focus();this.select();' size='65' /></p>";
- }
- }
- ?>
- <div id="local">
- <h2>Choose a file, by browsing your PC.</h2>
- <form method='POST' enctype='multipart/form-data' id='uploadLocalForm'>
- <input type="hidden" name="p" value="1" />
- <input type='file' name='imagefile' size="65" value="Click to browse..." /><br>
- <input type='submit' name='localUpload' value='Upload' /><br>
- </form></div>
- <div id="remote">
- <h2>Find an image on the web and paste the URL here.</h2>
- <form method='POST' enctype='multipart/form-data' name='uploadForm' id='form1'>
- <input type="hidden" name="p" value="1" />
- <input name='remoteimage' size="65" /><br>
- <input type='submit' name='remoteUpload' value='Upload' />
- </form></div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement