CMX Ads Webmaster Resources for Success

Websites, Advertising, Scripts Tips n Snippets

News: How Hackers Inject Data

Its cool and its compact its the cmxads Websites 2 Go image manager php script example

Hi there!. Here is another usefull Websites 2 Go addon script tutorial example for the people.
A read directory example script for images. Can be used as a stand alone website or a editing utility.
This little gem is set now for images but could easily be used for any files. This is a cut down/lite version of a
image manager in one of my application. This originally was meant to be embeded in a website editing area with login
and is used with a pop up sized to fit. And in the full version images are more than one folder. Usually
a thumbs file or page files. This script as it sits has the option to disable uploads, disable deleting, automatic thumbnails for jpg only. Has image size on hover, you can enable or disable delete and upload. You can set for max size and allowable extensions check out the script below.
Checkout the demo.


  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$img0000$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($dirpath0, -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:
?>
 

Click here for the script in a text file.


Rate me please.
Current Rating: 3.1 Thumbs up!
Vote 1 | Vote 2 | Vote 3 | Vote 4 | Vote 5

© 2021 CMXads.com Thumbs up rating script.


Please help me I am handicapped and support myself

Donate With PayPal

 

Donate Bitcoin

Please donate and help the handicapped.

1Ev8n7R63yqkKsFTrztufvuVah44MCbzpN



name:Moses Date:11.13.22 @ 01:43am IP:44124.2.22731.
Thanks you are cool I sent you 7 cents.


name:Shane Date:11.13.22 @ 00:52am IP:1221442...3274
Thanks you are cool I sent you 7 cents.


name:Katerine Date:08.7.22 @ 06:45am IP:.8291.34.11071
Thanks you are awesome. Working out good for me. I sent you 48 cents.


name:Kathrine Date:08.7.22 @ 06:45am IP:.79811.30.4112
Thanks you are awesome. Working out good for me. I sent you 48 cents.


name:Rachal Date:08.7.22 @ 06:44am IP:1810.49..73112
This worked out great for me too. I sent you 82 cents.


name:Rich Date:08.7.22 @ 06:28am IP:72114.9.803.11
Thanks I admire you I sent you 67 cents.


name:Kayleigh Date:08.7.22 @ 06:28am IP:2.1310.118.947
I found this very usefull thank you .


name:Kaleb Date:08.7.22 @ 06:28am IP:280.491..37111
Thanks you are cool I sent you 7 cents.


name:Ellyn Date:08.7.22 @ 05:58am IP:11742..80319.1
Thanks for sharing.


name:Freddy Date:08.7.22 @ 05:11am IP:71.0213..41819
Tyvm.


name:Janiece Date:08.7.22 @ 05:11am IP:41870921311...
Thanks for sharing.


name:Dave Date:08.7.22 @ 05:11am IP:81023.7141.19.
Thank you . I Sent you 5 cents.


name:Daphine Date:08.7.22 @ 05:11am IP:2730.181.1941.
Thanks for sharing.


name:Dave Date:08.7.22 @ 05:11am IP:89.1.1131720.4
This worked out great I sent you 19 cents.


name:Mark Date:08.7.22 @ 05:11am IP:8.1.0931141.72
This worked out great I sent you 19 cents.


name:Valorie Date:08.7.22 @ 05:11am IP:72.1.3081941.1
Thanks you are awesome. Working out good for me. I sent you 48 cents.


name:Krysten Date:08.7.22 @ 05:11am IP:18493117.1.20.
Thank you . I Sent you 5 cents.



Name:
Click Here to Reload

My websites do not use cookies or any google spyware.

 

Quick Support: Make it short.
Email:

Message: