1: <?php ini_set("memory_limit", "200000000"); ?>
2: <?php
3: // copyright 2022 cmxads websites 2 Go Image manager addon Utility
4: //set to create 100x100 jpg thumbnails into the imagedirectory/thumbnails/
5: $createThumb='1';
6: $maxsize='20000';
7: //path to image folder
8: $dir = dirname($_SERVER['SCRIPT_NAME']);
9:
10: $dirpath = 'imageul/';// set to the image folder this script reads from and uploads to
11:
12: $allowdelete = ''; // set for empty for demo. set 1 for production
13: $allowUpload = ''; // set for empty for demo. set 1 for production
14: if(isset($_GET['delete']) && $allowdelete){
15:
16: $delete=trim($_GET['delete']);
17: $delete1=$dirpath.$delete;
18:
19: if(file_exists($delete1)){
20: if(unlink($delete1)){
21: echo "<b>Image Deleted</b><br>";
22: }else{
23: echo "<b>Image Delete Error</b><br>";
24: }
25: }
26: }
27: //validate file ext
28: function getExtension($str) {
29: $i = strrpos($str,'.');
30: if (!$i) { return ''; }
31: $l = strlen($str) - $i;
32: $ext = substr($str,$i+1,$l);
33: return $ext;
34: }
35: //create thumbs function
36: function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth )
37: {
38: // open the directory
39: $dir = opendir( $pathToImages );
40:
41: // loop through it, looking for any/all JPG files:
42: while (false !== ($fname = readdir( $dir ))) {
43: // parse path for the extension
44: $info = pathinfo($pathToImages . $fname);
45: // continue only if this is a JPEG image
46: if ( @strtolower($info['extension']) == 'jpg' or @strtolower($info['extension']) == 'jpeg' or @strtolower($info['extension']) == 'jpe')
47: {
48: // echo "Created thumbnail for - {$fname} <br>";
49:
50: // load image and get image size
51: $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
52: $width = imagesx( $img );
53: $height = imagesy( $img );
54:
55: // calculate thumbnail size
56: $new_width = $thumbWidth;
57: $new_height = floor( $height * ( $thumbWidth / $width ) );
58:
59: // create a new temporary image
60: $tmp_img = imagecreatetruecolor( $new_width, $new_height );
61:
62: // copy and resize old image into new image
63: imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
64:
65: // save thumbnail into a file
66: imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
67: }
68: }
69: // close the directory
70: closedir( $dir );
71: }
72:
73: $submited='';
74: if($allowUpload) {
75: if(isset($_POST['submit2']) && !empty($_POST['submit2']))
76: {
77: $submited='yes';
78:
79: $path = $dirpath; //Folder where uploaded files go
80:
81: if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
82:
83: if ((($_FILES["userfile"]["type"] == "image/gif")
84: || ($_FILES["userfile"]["type"] == "image/jpg")
85: || ($_FILES["userfile"]["type"] == "image/jpe")
86: || ($_FILES["userfile"]["type"] == "image/gif")
87: || ($_FILES["userfile"]["type"] == "image/jpeg"))
88: && ($_FILES["userfile"]["size"] < $maxsize))
89: {
90: $filename = stripslashes($_FILES['userfile']['name']);
91: //get the extension of the file in a lower case format
92: $extension = getExtension($filename);
93: $extension = strtolower($extension);
94: //if it is not a known extension, we will suppose it is an error and will not upload the file,
95: //otherwise we will do more tests
96: //echo $extension;
97: if ($extension == "jpg" or $extension == "jpeg" or $extension == "gif")
98: {
99: $pass="1";
100: }else{
101: //print error message
102: echo '<h1>Unknown or unallowed file type!</h1>';
103: exit;
104: }
105:
106: if (file_exists($path . $_FILES['userfile']['name']))
107: {
108: echo 'A File With That Name Already Exists!<br>';
109: exit;
110: }
111: $filename = $_FILES['userfile']['name'];
112: $filename = strtolower($filename);
113: $filename=str_replace(" ","_", $filename);
114: $newfilename =$path;
115: $newfilename .=$filename;
116:
117: $res = copy($_FILES['userfile']['tmp_name'], $newfilename);
118:
119: if (!$res){
120: echo 'Upload Failed!<br>';
121: exit;
122: }
123: else{
124: //echo "Upload Successful!<br>";
125: if($createThumb){
126: if(!is_dir($dirpath."thumbnails/")){
127: mkdir($dirpath."thumbnails/", 755);
128: }
129:
130: createThumbs($dirpath,$dirpath . 'thumbnails/',100);
131: }
132: echo 'Upload Successful!<br>';
133: }}}}
134:
135: }// end if allowUpload
136:
137: $thelist='';
138: $dirpath = substr($dirpath, 0, -1);
139: // testing only
140: // $cycle = true;
141: // while ( $cycle !== false ) {
142: // $file = readdir( $dh);
143: // print ( "GOT a FILe or a FALSE:". $file ."<br>" );
144: // // do your stuff here
145: // $cycle = $file;
146: // }
147: //
148: // exit;
149: // initialize variables first
150: $handle = false;
151: $files = '';
152: // assign the handler
153: $handle = opendir($dirpath);
154:
155: $i="0";
156: // work only if necessary
157: if ( $handle !== false ) {
158: while ( ( $file = readdir( $handle ) ) !== false ) {
159: if (!is_dir($dirpath .'/'.$file) and $file != "." && $file != ".." && $file != "Thumbs.db" ) {
160: //gets image dimensions
161: list($width, $height) = getimagesize($dirpath.'/'.$file);
162: $i++;
163: $thelist .="($i) <img src=\"$dirpath/$file\" title=\"Width $width - Height $height\" width=\"60px\"> $file<br>";
164: //can set for full size image pop up
165: $thelist .=" <a href=\"$dirpath/$file\" onclick=\"return popitup2('$dirpath/$file')\"><b>View image</b></a>";
166: $thelist .= " - <span class=\"dropt\"><a href=\"listimages.php?delete=$file\">Delete</a><span style=\"width:200px;\">Are you sure you want to delete this image</span></span><br>";
167: }
168: }
169: closedir($handle);
170: }
171:
172: ?>
173:
174: <!DOCTYPE html>
175: <html lang="en">
176: <head>
177: <title>cmxads image and file upload manager free cool php script</title>
178: <meta charset="UTF-8">
179: <!--[if IE]><script
180: src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
181: <style type="text/css">
182: <!---
183: span.dropt:hover {text-decoration: none; background:white; z-index: 6; }
184: span.dropt span {position: absolute; left: -9999px;
185: margin: 20px 0 0 0px; padding: 3px 3px 3px 3px;
186: border-style:solid; border-color:red; border-width:2px; z-index: 6;}
187: span.dropt:hover span {left: 30%; background:white;}
188: --->
189: </style>
190:
191: <script type="text/javascript">
192: <!--
193: function popitup2(url) {
194: newwindow=window.open(url,'name2','height=300,width=300,left=300,top=0');
195: if (window.focus) {newwindow.focus()}
196: return false;
197: }
198:
199: // -->
200: </script>
201: <?php
202: echo "</head>";
203: echo "<body>";
204: echo '<div style="border: 2px solid #DB0202;border-radius: 15px;-khtml-border-radius: 15px;-moz-border-radius: 15px;-ms-border-radius: 15px;-o-border-radius: 15px; padding:10px;width:370px;margin: 0 auto;height:450px;">';
205: echo '<div style="width:350px;margin: 0 auto;height:350px;overflow-y: auto;">';
206: echo "<b><u>Just drag image/name where you want it.</u></b>";
207:
208: echo "<p>$thelist</p>";
209:
210: echo '</div>';
211: //if(!$submited)
212: //{
213: echo "<table><caption><strong><u>Upload Image jpg,jpeg,jpe,gif only(Max $maxsize)</u></strong></caption><tbody>";
214: echo "<tr class='mainrow'><td>";
215: echo "<form name='form1' method='post' action='' enctype='multipart/form-data'>";
216: echo "Select File:";
217: echo "<input type='file' name='userfile'> ";
218: echo "<input type='submit' name='submit2' value='upload'>";
219: echo "</form>";
220: echo "</td></tr></tbody></table>";
221: //}
222: echo "<a href=\"javascript:window.close();\">close window</a><br>";
223: echo '</div>';
224: echo "</body>";
225: echo "</html>";
226:
227: ?>