Jump to content

Need some help


Peter OHanlon

Recommended Posts

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

<?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="'.$imgurl.'" 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.'" />&lt/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

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

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

<?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="'.$imgurl.'" 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.'" />&lt/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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.