Advertisement
Guest User

Edited Code - Soft2050

a guest
Jul 10th, 2011
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.95 KB | None | 0 0
  1. <?php
  2.  
  3. //uncomment this when u have imagecfg.php
  4.  
  5. // include('imagecfg.php');
  6.  
  7. $siteURL = "http://localhost";
  8. $uploadDir = "images";
  9.     if ($_POST['localUpload']) {
  10.        
  11.         $name = $_FILES['imagefile']['name']; //file name
  12.         $type = $_FILES['imagefile']['type']; // type of file
  13.         $size = $_FILES['imagefile']['size']; //size of the mage in bytes
  14.         $tmp_name = $_FILES['imagefile']['tmp_name']; //temp file name and location
  15.         $ext = substr($name, strrpos($name, '.')); //grab file extension
  16.        
  17.         // Requirements
  18.         $dimension = getimagesize($tmp_name);
  19.         $width = $dimension[0];
  20.         $height = $dimension[1];
  21.  
  22.         // get the extension of the file in a lower case format
  23.          $ext = strtolower($ext);
  24.  
  25.     if (array($type, $allowed) && ($maxfileSize) && ( $width < $maxWidth && $height < $maxHeight )) {
  26.         $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
  27.         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
  28.        
  29.         echo "
  30.        <div align='center'>You've just successfully uploaded $name with the following specifications $size bytes and $width x $height px</div>
  31.      
  32.        <div align='center'><a href='$uploadDir/$name'><img src='$uploadDir/$name' alt='Uploaded image'></a></div>
  33.      
  34.        <div align='center'>Direct Image Links</div>
  35.      
  36.        <p align='center'>URL: <input tabindex='1' value='$siteURL/$uploadDir/$name' onclick='this.focus();this.select();' /></p>
  37.      
  38.        <p align='center'>HTML: <input tabindex='2' value='&lt;a href=&quot;$siteURL/$uploadDir/$name&quot;&gt;&lt;img src=&quot;$siteURL/$uploadDir/$name&quot; border=&quot;0&quot;&gt;&lt;/a&gt;' onclick='this.focus();this.select();' /></p>";
  39.        
  40.     }
  41.     else
  42.         echo "<p>You have submitted an invalid extension/larger file size than we accept or the dimensions are too big.</p>";
  43.  
  44.     } // < attempting a local upload and all checks.
  45. elseif (isset($_POST['remoteUpload'])) {
  46.        
  47.     $urls = explode("\n", $_POST['remoteimage']);
  48.     $imgarray = array();
  49.     foreach ($urls as $url)
  50.     {
  51.         $url = trim($url);
  52.         $imgname = strtotime(gmdate("M d Y H:i:s", time())) . '-' . basename($url);
  53.         $localimg = $uploadDir .'/'. $imgname;
  54.         $img = file_get_contents($url);
  55.         file_put_contents($localimg, $img);
  56.         $url = $baseurl . $imgname;
  57.         echo "<div align='center'>You've just successfully uploaded $imgname.</div>
  58.        
  59.        <div align='center'><a href='$localimg'><img src='$localimg' alt='Uploaded image'></a></div>
  60.        
  61.        <div align='center'>Direct Image Links</div>
  62.        
  63.        <p align='center'>URL: <input tabindex='1' value='$siteURL/$localimg' onclick='this.focus();this.select();' size='65' /></p>
  64.        
  65.        <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>";
  66.     }
  67.     }  
  68. ?>
  69. <div id="local">
  70. <h2>Choose a file, by browsing your PC.</h2>
  71.                 <form method='POST' enctype='multipart/form-data' id='uploadLocalForm'>
  72.                 <input type="hidden" name="p" value="1" />
  73.  
  74.         <input type='file' name='imagefile' size="65" value="Click to browse..." /><br>
  75.    
  76.             <input type='submit' name='localUpload' value='Upload' /><br>
  77. </form></div>
  78.  
  79. <div id="remote">
  80. <h2>Find an image on the web and paste the URL here.</h2>
  81.                 <form method='POST' enctype='multipart/form-data' name='uploadForm' id='form1'>
  82.                 <input type="hidden" name="p" value="1" />
  83.  
  84.         <input name='remoteimage' size="65" /><br>
  85.    
  86.             <input type='submit' name='remoteUpload' value='Upload' />
  87. </form></div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement