News:

Want to get involved in developing SMF? Why not lend a hand on our GitHub!

Main Menu

Code Review Needed

Started by The Wizard, December 15, 2012, 04:23:21 PM

Previous topic - Next topic

NanoSector

Quote from: The Wizard on December 18, 2012, 12:25:09 PM
ah ok so do you see any problem with the code?

Wiz
The code I gave you may or may not fix the problem, try it out :)
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

The Wizard

Thanks Yoshi2889 that fixes the problem. Below is the latest polished code (hopefully).
If anybody see's any issues please let me know.

Wiz


<?php

// =============================================================================
// Subs-Wizards_Add_Item.php                                
//
// Wizards Gallery: Gallery MOD for Simple Machines Forum Shop Mod                
// =============================================================================
//                                      
// Wizards Gallery by:         The Wizard ([email protected])  
// Version Number:             V 3.9d
// Copyright 2012 by:          The Wizard                                        
//
// Wizards Gallery was designed to be used with the Shop Mod for SMF
//
// SMF SHOP Software by:       DanSoft Australia (http://www.dansoftaustralia.net/)
// Copyright 2009 by:          vbgamer45 (http://www.smfhacks.com)                
// Copyright 2005-2007 by:     DanSoft Australia (http://www.dansoftaustralia.net/)
// Support, News, Updates at:  http://www.dansoftaustralia.net/                  
//                                                                                
// Forum software by:          Simple Machines (http://www.simplemachines.org)    
// Copyright 2006-2007 by:     Simple Machines LLC (http://www.simplemachines.org)
//           2001-2006 by:     Lewis Media (http://www.lewismedia.com)            
//
// Terms of the provided license:
// This program is free software; you may redistribute it and/or modify it.
// You are not allowed to sell this software, or package it in with software for sale.
//
// This program is distributed in the hope that it is, and will be useful, but    
// WITHOUT ANY WARRANTIES; without even any implied warranty of MERCHANTABILITY  
// or FITNESS FOR A PARTICULAR PURPOSE.
//                  
// ==============================================================================

if (!defined('SMF'))
die('Hacking attempt...');

Function
wizard_add_item()
{
global $sourcedir, $context, $txt, $boardurl, $scripturl;

loadTemplate('wizard_add_item_step1');

// add to launage file
$txt['wiz_file_uploaded'] = '<br />File Uploaded Successfully!';

// path to directory where big uploaded image goes
$upload_dir = $sourcedir . "/shop/Wizards_Gallery/big/";

// path to directory where created thumbnail goes
$thumbnail_dir = $sourcedir . "/shop/Wizards_Gallery/small/";

$image = $_FILES['image']['name'];

// combines big url with image name
$newname = $upload_dir . $image;

// With and Height of created thumbnail
$max_width  = 45;
$max_height = 45;

// error checking system set to zero
$errors = 0;

// Maximum Size a image can be
$max_file_size = 500;

// get the file exention of the uploaded image
$extension = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION);

// check and make sure the file exntion is only "png" if not do not upload and send error message  
if (isset($_POST['Submit']) && $extension != "png")
{
$errors                                 = 1;
$context['wizard_error_file_extension'] = $txt['wiz_file_extension_error'];
}

// check and make sure file size is not over limit if so do not upload and send error message
// this code only works with 'tmp_name'
$max_size = 500;
$size=filesize($_FILES['image']['tmp_name']);
if ($size > ($max_size * 500))
{
$errors                       = 1;
$context['wizard_error_size'] = $txt['wiz_size_error'];
}

// If there are no errors the upload image to big file if not do not upload and send error message
if (isset($_POST['Submit']) && !$errors)
{
move_uploaded_file($_FILES['image']['tmp_name'], $newname);
}
else
{
$errors                          = 1;
$context['wizard_error_general'] = $txt['wiz_general_error'];
}

// creates thumbnail and shows image of thumbnail in template
if (isset($_POST['Submit']) && !$errors)
{
require_once($sourcedir . '/Subs-Graphics.php');
$thumbnail                               = resizeImageFile($newname, $thumbnail_dir . $image, $max_width, $max_height);
$context['wizard_thumb_image']           = $boardurl . "/Sources/shop/Wizards_Gallery/small/" . $image;
$context['wizard_uploaded_successfully'] = $txt['wiz_file_uploaded'];

// Proceed to Step 2
$context['wizard_Step2'] = $scripturl . "?action=wizard_add_item_page2";
}
}
// End of Function wizard bracket

?>

emanuele

Quote from: Yoshi2889 on December 18, 2012, 11:11:06 AM
Quote from: The Wizard on December 18, 2012, 07:42:51 AM
Make long opening tag (<?php) from short one (<?)
Definitely yes. Some servers go all mad when you have just <? in your file; their PHP install doesn't allow it whereas <?php works on ALL PHP installations (unless it's broken).
Yups!
I read the the other way around...and I was not even drunk! :o
Yes, short tags are not such a good thing to use.

QuoteIndentation:4?
Now that I see the code, 1 is a better choice.

Quote from: The Wizard on December 18, 2012, 08:45:50 AM
Below is my nice shiny new code, but The size code DOES NOT WORK and I'm at a loss.
Of course, indentation style doesn't affect how code works...it's just a way to keep the code more readable and easier to debug.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Tyrsson

Do also keep in mind that short opening tags, even when running on a server with short opens enabled can still give problems with xml in certain situations.
PM at your own risk, some I answer, if they are interesting, some I ignore.

Advertisement: