Peter OHanlon Posted August 8, 2008 Share Posted August 8, 2008 I need some quick help with something please... http://www.petersserver.com/imagehost There is no problem with it, other than when a picture is uploaded, I would like to make it so just above the bars which tell the user what the link to their file is, I would like to display a thumbnailed version of the image they just uploaded. Thanks in advanced Link to comment https://forums.phpfreaks.com/topic/118823-need-some-help/ Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 We need to see some code to know what exactly you're doing, unless you just want us to throw generic thumbnail scripts at you. Link to comment https://forums.phpfreaks.com/topic/118823-need-some-help/#findComment-611830 Share on other sites More sharing options...
Peter OHanlon Posted August 8, 2008 Author Share Posted August 8, 2008 <?xml encoding="UTF-8"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>%SITENAME%</title> <link rel="stylesheet" type="text/css" media="screen" title="<?php print $title; ?> Cascading Stylesheet" href="style.css" /> <script type="text/javascript"> //<![CDATA[ window.onload = function() { if(window.location.hash) { document.getElementById('showimg').src = '%FILEDIR%/' + window.location.hash.substring(1); document.getElementById('showdiv').style.display = 'block'; } } //]]> </script> </head> <body> <h1>%SITENAME%</h1> </div> <div id="showdiv" style="display: none;"> <img id="showimg" alt="Loading image..." /> </div> <img src="%UPLOADEDPIC%"> <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { preg_match('/\.([a-zA-Z]+?)$/', $_FILES['file']['name'], $matches); if(in_array(strtolower($matches[1]), $accepted)) { if($_FILES['file']['size'] <= $maxsize) { $newname = md5_file($_FILES['file']['tmp_name']).'.'.$matches[1]; move_uploaded_file($_FILES['file']['tmp_name'], $filedir.'/'.$newname); $linkurl = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).'#'.$newname; $imgurl = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).$filedir.'/'.$newname; print '<h2>Upload Succesful!</h2> <p id="codes"><label for="codebb">Embed on bulletin boards:</label><br /> <input type="text" id="codebb" value="" onclick="javascript:this.focus();this.select();" readonly="true" /><br /> <label for="codehtml">Embed on webpages or MySpace: </label><br /> <input type="text" id="codehtml" value=\'<a href="'.$linkurl.'"><img src="'.$imgurl.' alt="Image hosting by '.$title.'" /></a>\' onclick="javascript:this.focus();this.select();" readonly="true" /><br /> <label for="codedirect">Direct link:</label><br /> <input type="text" id="codedirect" value="'.$imgurl.'" onclick="javascript:this.focus();this.select();" readonly="true" /></p>'; } else print '<p>Sorry, that file is too big.</p>'; } else print '<p>Sorry, that file type is not supported.</p>'; } ?> <form enctype="multipart/form-data" action="<?php print preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']) ?>" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="<?php print (ini_get('upload_max_filesize')>$maxsize)?ini_get('upload_max_filesize'):$maxsize; ?>" /> <label for="file">Upload an image: </label><input type="file" name="file" id="file" /> (must not be bigger than <?php print ((ini_get('upload_max_filesize')>$maxsize)?ini_get('upload_max_filesize'):$maxsize)/1024; ?> KiB)<br /> <input name="submit" type="submit" value="Upload" /> </form> <p id="footer"> Copyright © 2007 Peter O'Hanlon. <IMG SRC=http://www.petersserver.com/fireshank/power.gif>. </p> </body> </html> Thats the script I am using Link to comment https://forums.phpfreaks.com/topic/118823-need-some-help/#findComment-611834 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 You'll need to check out the GD library to load the file in and then resize it. Link to comment https://forums.phpfreaks.com/topic/118823-need-some-help/#findComment-611840 Share on other sites More sharing options...
Peter OHanlon Posted August 8, 2008 Author Share Posted August 8, 2008 Sorry, but I have no idea how to do this. Could you assist me please? Link to comment https://forums.phpfreaks.com/topic/118823-need-some-help/#findComment-611842 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 Probably something like: <?php $path = $_GET['path']; $ext = strrchr($path); switch ($ext) { case '.jpg': case '.jpeg': $im = imagecreatefromjpeg($path); $type = "jpeg"; break; case '.png': $im = imagecreatefrompng($path); $type = "png"; break; case '.gif'; $im = imagecreatefromgif($path); $type = "gif"; break; } $height = 100; $width = 100; $newimg = imagecreatetruecolor($width, $height); imagecopyresampled($newimg, $im, 0, 0, 0, 0, $width, $height, imagesx($im), imagesy($im)); $function = 'image' . $type; header("Content-Type: image/$type"); $function($im); ?> You'll need to work it a bit, but that should do it. Link to comment https://forums.phpfreaks.com/topic/118823-need-some-help/#findComment-611845 Share on other sites More sharing options...
Peter OHanlon Posted August 8, 2008 Author Share Posted August 8, 2008 And I just put that where I want it to go? Link to comment https://forums.phpfreaks.com/topic/118823-need-some-help/#findComment-611847 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 No. Put it in the folder of your script, and name it thumb.php. Then, inside your upload script, do something like: printf('<img src="thumb.php?path=%s />', urlencode($filedir . '/' . $newname)); thumb.php: <?php $path = urldecode($_GET['path']); $ext = strrchr($path); switch ($ext) { case '.jpg': case '.jpeg': $im = imagecreatefromjpeg($path); $type = "jpeg"; break; case '.png': $im = imagecreatefrompng($path); $type = "png"; break; case '.gif'; $im = imagecreatefromgif($path); $type = "gif"; break; } $height = 100; $width = 100; $newimg = imagecreatetruecolor($width, $height); imagecopyresampled($newimg, $im, 0, 0, 0, 0, $width, $height, imagesx($im), imagesy($im)); $function = 'image' . $type; header("Content-Type: image/$type"); $function($im); ?> Made a small change. Link to comment https://forums.phpfreaks.com/topic/118823-need-some-help/#findComment-611851 Share on other sites More sharing options...
Peter OHanlon Posted August 8, 2008 Author Share Posted August 8, 2008 I have no idea why, but it's still not displaying the picture Link to comment https://forums.phpfreaks.com/topic/118823-need-some-help/#findComment-611858 Share on other sites More sharing options...
Jabop Posted August 8, 2008 Share Posted August 8, 2008 Did you not write this site yourself? I would assume if you're apt enough to write a php uploader script, that you could find the sources to write a php-gd image resizer. Link to comment https://forums.phpfreaks.com/topic/118823-need-some-help/#findComment-611863 Share on other sites More sharing options...
Peter OHanlon Posted August 8, 2008 Author Share Posted August 8, 2008 No, a friend wrote this for me.And he has gone away for a while, so I need help. At the monent, it's displaying a broken image, so at least it is getting somewhere Link to comment https://forums.phpfreaks.com/topic/118823-need-some-help/#findComment-611866 Share on other sites More sharing options...
Jabop Posted August 8, 2008 Share Posted August 8, 2008 Did you assign the variables that DarkWater provided accordingly? Link to comment https://forums.phpfreaks.com/topic/118823-need-some-help/#findComment-611868 Share on other sites More sharing options...
Peter OHanlon Posted August 8, 2008 Author Share Posted August 8, 2008 This is what I did : printf('<img src="thumb.php?path=%s /pics>', urlencode($filedir . '/pics' . $newname)); Because the folder containing the images is /pics And I used the thumb.php acordingly. Link to comment https://forums.phpfreaks.com/topic/118823-need-some-help/#findComment-611869 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 Replace the pics part and use just /. I concatenated $filedir already... Link to comment https://forums.phpfreaks.com/topic/118823-need-some-help/#findComment-611870 Share on other sites More sharing options...
Peter OHanlon Posted August 8, 2008 Author Share Posted August 8, 2008 <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { preg_match('/\.([a-zA-Z]+?)$/', $_FILES['file']['name'], $matches); if(in_array(strtolower($matches[1]), $accepted)) { if($_FILES['file']['size'] <= $maxsize) { $newname = md5_file($_FILES['file']['tmp_name']).'.'.$matches[1]; move_uploaded_file($_FILES['file']['tmp_name'], $filedir.'/'.$newname); printf('<img src="thumb.php?path=%s />', urlencode($filedir . '/' . $newname)); $linkurl = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).'#'.$newname; $imgurl = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).$filedir.'/'.$newname; print '<h2>Upload Succesful!</h2> <p id="codes"><label for="codebb">Embed on bulletin boards:</label><br /> <input type="text" id="codebb" value="" onclick="javascript:this.focus();this.select();" readonly="true" /><br /> <label for="codehtml">Embed on webpages or MySpace: </label><br /> <input type="text" id="codehtml" value=\'<a href="'.$linkurl.'"><img src="'.$imgurl.'" alt="Image hosting by '.$title.'" /></a>\' onclick="javascript:this.focus();this.select();" readonly="true" /><br /> <label for="codedirect">Direct link:</label><br /> I already tried that, and it's still the same Link to comment https://forums.phpfreaks.com/topic/118823-need-some-help/#findComment-611871 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 I just noticed that you never even set $filedir...are pics uploading correctly at all? Link to comment https://forums.phpfreaks.com/topic/118823-need-some-help/#findComment-611874 Share on other sites More sharing options...
Peter OHanlon Posted August 8, 2008 Author Share Posted August 8, 2008 They just come up as broken images The actual links work to the pic just not displaying it. Link to comment https://forums.phpfreaks.com/topic/118823-need-some-help/#findComment-611877 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 Check the folder in which the pics should be uploaded to on your server. >_> Make sure they're intact. Link to comment https://forums.phpfreaks.com/topic/118823-need-some-help/#findComment-611880 Share on other sites More sharing options...
Peter OHanlon Posted August 8, 2008 Author Share Posted August 8, 2008 Images upload fine, I just need to get it to thumbnail on that page now. Link to comment https://forums.phpfreaks.com/topic/118823-need-some-help/#findComment-611886 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.