Advertisement

05.01.2008 at 10:11PM PDT, ID: 23370774
[x]
Attachment Details

Image Dimensions Part 2

Asked by pertrai1 in PHP and Databases, PHP Scripting Language

Tags: php & databases

Hi, ali helped me out on some of this so far. We have come to determine that I need my memory_limit increased in php.ini. Only problem is that I do not have access to this and my web host is not playing nice. So here is my question: Would this work:

ini_set("memory_limit","24M");

I saw it somewhere and I tried it and it did not. But, I do not know if I was using it correctly. If this would help with my php.ini problem, how would I implement this into my script and where?

Thanks much.

RobStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482:
<?php
 
/*
 
	Upload an image and create the thumbnail. The thumbnail is stored 
 
	under the thumbnail sub-directory of $uploadDir.
 
	
 
	Return the uploaded image name and the thumbnail also.
 
*/
 
function uploadImage($inputName, $uploadDir)
 
{
 
	$image     = $_FILES[$inputName];
 
	$imagePath = '';
 
	$thumbnailPath = '';
 
	
 
	// if a file is given
 
	if (trim($image['tmp_name']) != '') {
 
		$ext = strtolower(substr(strrchr($image['name'], "."), 1)); 
 
 
 
		// generate a random new file name to avoid name conflict
 
		// then save the image under the new file name
 
		$imagePath = md5(rand() * time()) . ".$ext";
 
		$result    = move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath . "_");
		
		// resize image to 600px X ? if needed
		copyImage($uploadDir . $imagePath . "_", $uploadDir . $imagePath, null, null, 75, true);
		unlink($uploadDir . $imagePath . "_");
 
			
 
		if ($result) {
 
			// create thumbnail
			$thumbnailPath =  md5(rand() * time()) . ".$ext";
 
			$result = createThumbnail($uploadDir . $imagePath, $uploadDir . 'thumbnail/' . $thumbnailPath, THUMBNAIL_WIDTH);
 
			
 
			// create thumbnail failed, delete the image
 
			if (!$result) {
 
				unlink($uploadDir . $imagePath);
 
				$imagePath = $thumbnailPath = '';
 
			} else {
 
				$thumbnailPath = $result;
 
			}	
 
		} else {
 
			// the image cannot be uploaded
 
			$imagePath = $thumbnailPath = '';
 
		}
 
		
 
	}
 
 
 
	
 
	return array('image' => $imagePath, 'thumbnail' => $thumbnailPath);
 
}
 
 
 
/*
 
	Create a thumbnail of $srcFile and save it to $destFile.
 
	The thumbnail will be $width pixels.
 
*/
 
function createThumbnail($srcFile, $destFile, $width, $quality = 75)
 
{
 
	$thumbnail = '';
 
	
 
	if (file_exists($srcFile)  && isset($destFile))
 
	{
 
		$size        = getimagesize($srcFile);
 
		$w           = number_format($width, 0, ',', '');
 
		$h           = number_format(($size[1] / $size[0]) * $width, 0, ',', '');
 
		
 
		$thumbnail =  copyImage($srcFile, $destFile, $w, $h, $quality);
 
	}
 
	
 
	// return the thumbnail file name on sucess or blank on fail
 
	return basename($thumbnail);
 
}
 
 
 
/*
 
	Copy an image to a destination file. The destination
 
	image size will be $w X $h pixels
 
*/
 
function copyImage($srcFile, $destFile, $w, $h, $quality = 75,$resize=false)
 
{
 
    $tmpSrc     = pathinfo(strtolower($srcFile));
 
    $tmpDest    = pathinfo(strtolower($destFile));
 
    $size       = getimagesize($srcFile);
 
if ($resize == true)
	{
	    if ($size[0] > 600)
	    {
	        // Resize image so we have a width of 600px
	        $newWidth = 600;
	        $ratio = $size[0] / $newWidth;
	        $newHeight = $size[1] / $ratio; 
	    }
	    else
	    {
	        // Keep the same image size
	        $newWidth = $size[0];
	        $newHeight = $size[1];
	    }
	}
	else
	{
		$newWidth = $w;
		$newHeight = $h;
	}
 
    if ($tmpDest['extension'] == "gif" || $tmpDest['extension'] == "jpg")
 
    {
 
       $destFile  = substr_replace($destFile, 'jpg', -3);
 
       $dest      = imagecreatetruecolor($newWidth, $newHeight);
 
       //imageantialias($dest, TRUE);
 
    } elseif ($tmpDest['extension'] == "png") {
 
       $dest = imagecreatetruecolor($newWidth, $newHeight);
 
       //imageantialias($dest, TRUE);
 
    } else {
 
      return false;
 
    }
 
 
 
    switch($size[2])
 
    {
 
       case 1:       //GIF
 
           $src = imagecreatefromgif($srcFile);
 
           break;
 
       case 2:       //JPEG
 
           $src = imagecreatefromjpeg($srcFile);
 
           break;
 
       case 3:       //PNG
 
           $src = imagecreatefrompng($srcFile);
 
           break;
 
       default:
 
           return false;
 
           break;
 
    }
 
 
 
    imagecopyresampled($dest, $src, 0, 0, 0, 0, $newWidth, $newHeight, $size[0], $size[1]);
 
 
 
    switch($size[2])
 
    {
 
       case 1:
 
       case 2:
 
           imagejpeg($dest,$destFile, $quality);
 
           break;
 
       case 3:
 
           imagepng($dest,$destFile);
 
    }
 
    return $destFile;
 
 
 
}
 
 
 
/*
 
	Check if the user is logged in or not
 
*/
 
/*function checkLogin()
 
{
 
	if (!isset($_SESSION['isLogin']) || $_SESSION['isLogin'] == false) {
 
		header('Location: login.php');
 
		exit;
 
	}
 
}
 
 
 
/*
 
	Create the link for moving from one page to another
 
*/
 
function getPagingLink($totalResults, $pageNumber, $itemPerPage = 10, $strGet = '')
 
{
 
	$pagingLink    = '';
 
	$totalPages    = ceil($totalResults / $itemPerPage);
 
	
 
	// how many link pages to show
 
	$numLinks      = 10;
 
 
 
	// create the paging links only if we have more than one page of results
 
	if ($totalPages > 1) {
 
		$self = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ;
 
 
 
		// print 'previous' link only if we're not
 
		// on page one
 
		if ($pageNumber > 1) {
 
			$page = $pageNumber - 1;
 
			if ($page > 1) {
 
				$prev = " <a href=\"$self?pageNum=$page&$strGet\" class=\"gray\">[Prev]</a> ";
 
			} else {
 
				$prev = " <a href=\"$self?$strGet\" class=\"gray\">[Prev]</a> ";
 
			}	
 
				
 
			$first = " <a href=\"$self?$strGet\" class=\"gray\">[First]</a> ";
 
		} else {
 
			$prev  = ''; // we're on page one, don't show 'previous' link
 
			$first = ''; // nor 'first page' link
 
		}
 
	
 
		// print 'next' link only if we're not
 
		// on the last page
 
		if ($pageNumber < $totalPages) {
 
			$page = $pageNumber + 1;
 
			$next = " <a href=\"$self?pageNum=$page&$strGet\" class=\"gray\">[Next]</a> ";
 
			$last = " <a href=\"$self?pageNum=$totalPages&$strGet\" class=\"gray\">[Last]</a> ";
 
		} else {
 
			$next = ''; // we're on the last page, don't show 'next' link
 
			$last = ''; // nor 'last page' link
 
		}
 
 
 
		$start = $pageNumber - ($pageNumber % $numLinks) + 1;
 
		$end   = $start + $numLinks - 1;		
 
		
 
		$end   = min($totalPages, $end);
 
		
 
		$pagingLink = array();
 
		for($page = $start; $page <= $end; $page++)	{
 
			if ($page == $pageNumber) {
 
				$pagingLink[] = " $page ";   // no need to create a link to current page
 
			} else {
 
				if ($page == 1) {
 
					$pagingLink[] = " <a href=\"$self?$strGet\" class=\"gray\">$page</a> ";
 
				} else {	
 
					$pagingLink[] = " <a href=\"$self?pageNum=$page&$strGet\" class=\"gray\">$page</a> ";
 
				}	
 
			}
 
	
 
		}
 
		
 
		$pagingLink = implode(' | ', $pagingLink);
 
		
 
		// return the page navigation link
 
		$pagingLink = $first . $prev . $pagingLink . $next . $last;
 
	}
 
	
 
	return $pagingLink;
 
}
 
 
 
/*
 
	Display the breadcrumb navigation on top of the gallery page
 
*/
 
function showBreadcrumb()
 
{
 
	if (isset($_GET['album'])) { 
 
		$album = $_GET['album'];
 
		$sql  = "SELECT al_name
 
                 FROM tbl_album
 
		         WHERE al_id = $album";
 
				 
 
		$result = mysql_query($sql) or die('Error, get album name failed. ' . mysql_error());
 
		$row = mysql_fetch_assoc($result);
 
		echo ' &gt; <a href="index.php?page=list-image&album=' . $album . '" class="gray">' . $row['al_name'] . '</a>';
 
 
 
		if (isset($_GET['image'])) {
 
			$image = $_GET['image'];
 
			$sql  = "SELECT im_title
 
					 FROM tbl_image
 
					 WHERE im_id = $image";
 
					 
 
			$result = mysql_query($sql) or die('Error, get image name failed. ' . mysql_error());
 
			$row = mysql_fetch_assoc($result);
 
			
 
			echo ' &gt; <a href="index.php?page=image-detail&album=' . $album . '&image=' . $image . '" class="gray">' . $row['im_title'] . '</a>';
 
		}
 
	}
 
}
 
 
 
?>
 
Loading Advertisement...
 
[+][-]05.01.2008 at 11:02PM PDT, ID: 21484790

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.02.2008 at 04:03AM PDT, ID: 21485696

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.02.2008 at 05:49AM PDT, ID: 21486176

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.02.2008 at 06:12AM PDT, ID: 21486309

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP and Databases, PHP Scripting Language
Tags: php & databases
Sign Up Now!
Solution Provided By: ali_kayahan
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05.02.2008 at 06:29AM PDT, ID: 21486434

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.02.2008 at 06:41AM PDT, ID: 21486528

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.02.2008 at 07:13AM PDT, ID: 21486807

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.02.2008 at 07:17AM PDT, ID: 21486839

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.02.2008 at 07:19AM PDT, ID: 21486856

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628