 |
boardom b2 message board
|
View previous topic :: View next topic |
Author |
Message |
voltaic
Joined: 05 Jan 2004 Posts: 5 Location: The 9. 1. 6.
|
Posted: Mon Jan 05, 2004 9:37 pm Post subject: Thumbnail Uploads |
|
|
Here's another nice mod (although it is definitely more like a hack) for your b2 blog. This hack modifies the uploads popup so that you can do two files at a time if you want to have a thumbnail point to a larger main image. The nice thing about the hack is instead of uploading two files and then hand-writing HTML to do the popup, it does it all for you! We use this hack to do thumbnail popups at DIY Games and it seems to work well.
We got rid of the old b2upload.php file and made an entirely new one. Also we don't have alot of duplicate images, so I removed the part of the file upload where it confirms that you want to rename duplicate files. Instead, this script renames them by default.
Code: | <?php
/* b2 File Upload - original hack by shockingbird.com */
/* modified by VOLTMAN! to do thumbnails */
$standalone="1";
require_once("./b2header.php");
if ($user_level < 3) //Checks to see if user has logged in
die ("Cheatin' uh ?");
if (!$use_fileupload) //Checks if file upload is enabled in the config
die ("The admin disabled this function");
?><html>
<head>
<title>b2 > upload images/files</title>
<link rel="stylesheet" href="<?php echo $b2inc; ?>/b2.css" type="text/css">
<?php if ($use_spellchecker) { ?>
<script type="text/javascript" language="javascript" src="<?php echo $spch_url; ?>"></script><?php } ?>
<style type="text/css">
<!--
body {
background-image: url('<?php
if ($is_gecko || $is_macIE) {
?>b2-img/bgbookmarklet1.gif<?php
} else {
?>b2-img/bgbookmarklet3.gif<?php
}
?>');
background-repeat: no-repeat;
margin: 30px;
}
<?php
if (!$is_NS4) {
?>
textarea,input,select {
background-color: white;
/*<?php if ($is_gecko || $is_macIE) { ?>
background-image: url('b2-img/bgbookmarklet.png');
<?php } elseif ($is_winIE) { ?>
background-color: #cccccc;
filter: alpha(opacity:80);
<?php } ?>
*/ border-width: 1px;
border-color: #cccccc;
border-style: solid;
padding: 2px;
margin: 1px;
}
<?php if (!$is_gecko) { ?>
.checkbox {
border-width: 0px;
border-color: transparent;
border-style: solid;
padding: 0px;
margin: 0px;
}
.uploadform {
background-color: white;
<?php if ($is_winIE) { ?>
filter: alpha(opacity:100);
<?php } ?>
border-width: 1px;
border-color: #333333;
border-style: solid;
padding: 2px;
margin: 1px;
width: 265px;
height: 24px;
}
<?php } ?>
<?php
}
?>
-->
</style>
<script type="text/javascript">
<!-- // idocs.com's popup tutorial rules !
function targetopener(blah, closeme, closeonly) {
if (! (window.focus && window.opener))return true;
window.opener.focus();
if (! closeonly)window.opener.document.post.content.value += blah;
if (closeme)window.close();
return false;
}
//-->
</script>
</head>
<body>
<table align="center" width="100%" height="100%" cellpadding="15" cellspacing="0" border="1" style="border-width: 1px; border-color: #cccccc;">
<tbody>
<tr>
<td valign="top" style="background-color: transparent; <?php if ($is_gecko || $is_macIE) { ?>background-image: url('b2-img/bgbookmarklet.png');<?php } elseif ($is_winIE) { ?>background-color: #cccccc; filter: alpha(opacity:60);<?php } ?>;">
<?php
if (!$HTTP_POST_VARS["submit"]) {
$i = explode(" ",$fileupload_allowedtypes);
$i = implode(", ",array_slice($i, 1, count($i)-2));
?>
<p><strong>File upload</strong><br />
You can upload <em><?php echo $i ?></em> images.</p>
<!-- <p>The maximum size of each file is <em><?php echo $fileupload_maxk ?> KB</em></p> -->
<form action="b2upload.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $fileupload_maxk*1024 ?>" />
Small picture / thumbnail:
<input type="file" name="img1" size="30" class="uploadform" /><br />
Description:<br />
<input type="text" name="imgdesc" size="30" class="uploadform" /><br />
<br /><br />
Big picture <b>if</b> there is a thumbnail:
<input type="file" name="img2" size="30" class="uploadform" /><br />
(same description as the thumbnail)<br />
<br /><br />
<input type="submit" name="submit" value="upload !" class="search" />
</form>
</td>
</tr>
</tbody>
</table>
</body>
</html><?php die();
}
?>
<?php //Makes sure they choose a file
//print_r($HTTP_POST_FILES);
//die();
if (!empty($HTTP_POST_VARS)) { //$img1_name != "") {
$img1_name = (strlen($img1alt)) ? $HTTP_POST_VARS['img1alt'] : $HTTP_POST_FILES['img1']['name'];
$img1_type = (strlen($img1alt)) ? $HTTP_POST_VARS['img1_type'] : $HTTP_POST_FILES['img1']['type'];
$img2_name = (strlen($img2alt)) ? $HTTP_POST_VARS['img2alt'] : $HTTP_POST_FILES['img2']['name'];
$img2_type = (strlen($img2alt)) ? $HTTP_POST_VARS['img2_type'] : $HTTP_POST_FILES['img2']['type'];
$imgdesc = str_replace('"', '"', $HTTP_POST_VARS['imgdesc']);
$img1type = explode(".",$img1_name);
$img1type = " ".$img1type[count($img1type)-1]." ";
$img2type = explode(".",$img2_name);
$img2type = " ".$img2type[count($img2type)-1]." ";
if (!ereg(strtolower($img1type), strtolower($fileupload_allowedtypes))) {
die("File $img1_name of type $img1type is not allowed.");
}
if (strlen($img2_name)>2 AND !ereg(strtolower($img2type), strtolower($fileupload_allowedtypes))) {
die("File $img2_name of type $img2type is not allowed.");
}
$pathtofile1 = $fileupload_realpath."/".$img1_name;
$pathtofile2 = $fileupload_realpath."/".$img2_name;
$img1 = $HTTP_POST_FILES['img1']['tmp_name'];
$img2 = $HTTP_POST_FILES['img2']['tmp_name'];
// adds numbers to end of duplicates
// no longer checks with user
$i=1;
while (file_exists($pathtofile1)) {
$pos = strpos($pathtofile1, '.'.trim($img1type));
if( $i>1 ) $pos-=3;
$pathtofile_start = substr($pathtofile1, 0, $pos);
$pathtofile1 = $pathtofile_start.'_'.zeroise($i++, 2).'.'.trim($img1type);
$findimg = explode('/', $pathtofile1);
$img1_name = $findimg[count($findimg)-1];
}
$j=1;
if(strlen($img2_name)){
while (file_exists($pathtofile2)) {
$pos = strpos($pathtofile2, '.'.trim($img2type));
if( $j>1 ) $pos-=3;
$pathtofile_start = substr($pathtofile2, 0, $pos);
$pathtofile2 = $pathtofile_start.'_'.zeroise($j++, 2).'.'.trim($img2type);
$findimg = explode('/', $pathtofile2);
$img2_name = $findimg[count($findimg)-1];
}
}
if (!strlen($img1alt)) {
move_uploaded_file($img1, $pathtofile1) //Path to your images directory, chmod the dir to 777
or die("1: Couldn't Upload Your File to $pathtofile1.");
} else {
rename($img1, $pathtofile1) or die("2: Couldn't Upload Your File to $pathtofile1.");
}
if( strlen( $img2_name ) > 2 ) {
if (!strlen($img2alt)) {
move_uploaded_file($img2, $pathtofile2) //Path to your images directory, chmod the dir to 777
or die("1: Couldn't Upload Your File to $pathtofile2.");
} else {
rename($img2, $pathtofile2) or die("2: Couldn't Upload Your File to $pathtofile2.");
}
}
}
if( strlen( $img2_name ) < 2 ) { // no thumbnail
$piece_of_code ="<img src="$fileupload_url/$img1_name" border=0 alt="$imgdesc" />";
} else { // yes thumbnail
$piece_of_code ="<a href="$fileupload_url/$img2_name" onclick="b2open(this.href); return false" />";
$piece_of_code.="<img src="$fileupload_url/$img1_name" border=0 alt="$imgdesc" />";
$piece_of_code.="</a>";
}
?>
<p><strong>File uploaded !</strong></p>
<p>The file <b><?php echo "$img1_name"; ?></b> is OK !
<?php
if( strlen( $img2_name )>2 ) {
?>
<br />The file <b><?php echo "$img2_name"; ?></b> is also OK !
<?php
}
?>
</p>
<p>Here's the code to display it:</p>
<p><form>
<input type="text" name="imgpath" value="<?php echo $piece_of_code; ?>" size="38" style="padding: 5px; margin: 2px;" /><br />
<input type="button" name="close" value="Add the code to your post !" class="search" onClick="targetopener('<?php echo $piece_of_code; ?>')" style="margin: 2px;" />
</form>
</p>
<?php
if( strlen( $img2_name ) < 2 ) {
?>
<p><strong>Image Details</strong>: <br />
name: <?php echo "$img1_name"; ?> <?php if($i>1) echo "(renamed)"; ?><br />
size: <?php echo round($img1_size/1024,2); ?> KB<br />
type: <?php echo "$img1_type"; ?></p>
<?php
} else {
?>
<p><strong>Thumbnail</strong> Details: <br />
name: <?php echo "$img1_name"; ?> <?php if($i>1) echo "(renamed)"; ?><br />
size: <?php echo round($img1_size/1024,2); ?> KB<br />
type: <?php echo "$img1_type"; ?><br /><br />
<strong>Large Image</strong> Details: <br />
name: <?php echo "$img2_name"; ?> <?php if($j>1) echo "(renamed)"; ?><br />
size: <?php echo round($img2_size/1024,2); ?> KB<br />
type: <?php echo "$img2_type"; ?></p>
<?php
}
?>
<p align="right">
<form>
<input type="button" name="close" value="Close this window" class="search" onClick="window.close()" />
</form>
</p>
</td>
</tr>
</tbody>
</table>
</body>
</html> |
To use this is simple. If you have an image that is NOT a thumbnail link, only fill in the top filename and description. If you have an image that IS a thumbnail link, fill in the top filename with the thumbnail image, fill in a description, then fill in the bottom filename with the main/large image. Nice!
Notice: This code is released under the terms of the GNU General Public License for use by anyone for anything. Do with it as you see fit. |
|
Back to top |
|
 |
voltaic
Joined: 05 Jan 2004 Posts: 5 Location: The 9. 1. 6.
|
Posted: Mon Jan 05, 2004 9:50 pm Post subject: |
|
|
Here's a screenshot of the new thumbnail-ready upload tool if you are interested in seeing it:
|
|
Back to top |
|
 |
CSBBSHF
Joined: 03 Feb 2004 Posts: 2
|
Posted: Tue Feb 03, 2004 4:43 am Post subject: |
|
|
hi just a litte problem with this...
Code: | Warning: move_uploaded_file(/home/csbbshf/public_html/b2/images/mon.jpg): failed to open stream: Permission denied in /home/csbbshf/public_html/b2/b2upload.php on line 183
Warning: move_uploaded_file(): Unable to move '/tmp/phpOmpoI2' to '/home/csbbshf/public_html/b2/images/mon.jpg' in /home/csbbshf/public_html/b2/b2upload.php on line 183
1: Couldn't Upload Your File to /home/csbbshf/public_html/b2/images/mon.jpg. |
Any suggestions? Thanks...
I had the line Code: | # accepted file types, you can add to that list if you want
# note: add a space before and after each file type
# example: $fileupload_allowedtypes = ' jpg gif png ';
$fileupload_allowedtypes = ' jpg gif png mpg mov '; |
in my b2 config and i changed it to delet the mpg and mov filetypes... didnt do anything. |
|
Back to top |
|
 |
CSBBSHF
Joined: 03 Feb 2004 Posts: 2
|
Posted: Tue Feb 03, 2004 11:28 pm Post subject: |
|
|
ok fixed it! Read through b2upload.php and realized my /images directory had to be CHMODed to 777. So once again if stuck it always helps to RTFM  |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB 2 © 2001, 2002 phpBB Group
|