...

View Full Version : PHP getimagesize



UrbanTwitch
09-02-2009, 03:34 AM
Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in C:\wamp\www\crafthub\tools.php on line 82


<?php
include("includes/verytop.php");
?>
<title>Tools - CraftHub</title>
<?php
include("includes/main.php");

switch ($_GET['act']) {

default:
function highlightWords($text, $words)
{
/*** loop of the array of words ***/
foreach ($words as $word)
{
/*** quote the text for regex ***/
$word = preg_quote($word);
/*** highlight the words ***/
$text = preg_replace("/\b($word)\b/i", '<span class="highlight_word">\1</span>', $text);
}
/*** return the text ***/
return $text;
}


/*** example usage ***/
$string = 'This text will highlight PHP and SQL and sql but not PHPRO or MySQL or sqlite';
/*** an array of words to highlight ***/
$words = array('php', 'sql');
$result = count($words);
/*** highlight the words ***/
$string = highlightWords($string, $words);
echo "
$result


<style>
.highlight_word{
background-color: yellow;
color:black;
}
</style>";

echo $string;

break;

case 'submit':
if (!$_POST['submit']) {
echo "

<form action='tools.php?act=submit' method='post'>
<div id='contentbox'>
<div class='hd'>Submit your tool!</div>
<div class='cwrap'>
<div id='warning'>All submitted tools must be Minecraft related. Additionaly, the Tool picture is <strong>optional</strong>. For the tool picture, you can only upload GIFs or JPEG/JPGS.</div>
<div class='cwrap'>
<fieldset><legend>Tool Name</legend>
<input type='text'name='title' size='30' /></fieldset><br />
<fieldset><legend>Tool Website</legend>
<input type='text'name='site' size='30' value='http://' /></fieldset><br />
<fieldset><legend>Tool Creator?</legend>
<input type='text'name='by' size='30' /></fieldset><br />
<fieldset><legend>Tool Description </legend>
<textarea name='desc' style='width:99%;' rows='5'></textarea></fieldset><br />
<fieldset><legend><label for='file'><b>Tool Picture (125x125 pixels)</b></label></legend>
<input type='file' name='toll' /></fieldset><br />


<input type='submit' value='Submit Tool' name='submit'></div></div></form>";

}else{
$filename = $_FILES["toolimg"]["name"];
$tmp_name = $_FILES["toolimg"]["tmp_name"];

$chars = "abcdefghijklmnopqrstuvwxyz1234567890"; //available chars
$uniqueurl = substr(str_shuffle($chars), 0, 10); // shuffles the string $chars and picks the first 10
$toolimg = "images/toolimgs/$uniqueurl".$filename;
$username = $logged[username];
$file = $_FILES['userfile'];
$imgtype = $_FILES["toolimg"]["type"];
$imageInfo = getimagesize($_FILES["toolimg"]["tmp_name"]);
if (($imageInfo["mime"] == "image/gif") || ($imageInfo["mime"] == "image/jpeg") || ($imageInfo["mime"] == "image/png") || ($imageInfo["mime"] == "image/jpg"))

{



$my_image = array_values(getimagesize($tmp_name));
//use list on new array
list($width, $height, $type, $attr) = $my_image;
if ($width > 100 || $height > 100) {
echo "<div id='error'>The image you are uploading is too big and will not be uploaded.</div>";
}elseif (preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', $site)) {
//$insert_tool = mysql_query("INSERT INTO `tools` (`title` ,`desc` ,`site` ,`by`, `appear`) VALUES ('$title', '$desc', '$site', '$by', 'no');") or die(mysql_error());
//$do_upload = move_uploaded_file($_FILES["file"]["tmp_name"], "toolimgs/$uniqueurl" . $_FILES["file"]["name"]);
echo "<div id='contentbox'>
<div class='hd'>Success!</div>
<div class='cwrap'>All tool submissions will be reviewed by any Operator, Staff, or Administrator that is online. If the tool is accepted, it will display on the website. Thanks for submitting!</div></div>";

}
}


}






break;

case 'manage':
if ($logged['userlevel'] == '6' || $logged['userlevel'] == '4' || $logged['userlevel'] == '3') {
echo "<div id='contentbox'>
<div class='hd'>Manage Tool Submissions</div>
<div class='cwrap'>You're job isn't hard here. If you see a tool that related to Minecraft and helps the community, accept it. If not, decline it.<br />

</div></div>";
$result2 = mysql_query("SELECT * FROM `forum_thread` WHERE `thr_id` = '$_GET[id]' AND `sticky` = 'Yes' ORDER BY `datetwo` DESC");


$fetch = mysql_query("SELECT * FROM `forum_topic` WHERE `id` = '$_GET[id]'");
$ce = mysql_fetch_array($fetch);





if (isset($_POST['Submit3']) && $_POST['Submit3'] == 'apply')
{
$id = array();
$id = $_POST['removeid'];
//print_r($id);
if (count($id) > 0)
{
$mode = $_POST[moderate];

echo "<div style='margin-bottom:5px;' id='success'>Tools have been moderated.</div><br />";

foreach ($id as $removeid)
{

$mod = $_POST[moderate];
if ($mod == 'yes') {
$update_tools_1 = mysql_query("UPDATE `tools` SET `appear` = 'yes' WHERE id = '$removeid'") or die(mysql_error());
}elseif($mod == 'no') {
$update_tools_1 = mysql_query("UPDATE `tools` SET `appear` = 'no' WHERE id = '$removeid'") or die(mysql_error());
}

}

}
}

$sql = "SELECT COUNT(*) FROM `tools` WHERE `appear` = 'no'";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$msgs = mysql_query("SELECT * FROM `tools` WHERE `appear` = 'no'") or die(mysql_error()); //get all the
$a = mysql_fetch_array($msgs);
$numxrows = mysql_num_rows($msgs);
$numrows = $numxrows;
// number of rows to show per page
$rowsperpage = 10;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);
// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
} // end if
// if current page is greater than total pages...
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
// get the info from the db
$sql = "SELECT * FROM `tools` WHERE `appear` = 'no' ORDER BY `id` DESC LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);


/****** end build pagination links ******/

echo "<br /><form action='tools.php?act=mod&id=$_GET[id]&moderate' method='post'>
<script type='text/javascript' src='http://www.shawnolson.net/scripts/public_smo_scripts.js'></script>
<div id='contentbox'>
<div class='hd'>Tool Option</div>
<div class='cwrap'><span style='float:right;'>Select all: <input type='checkbox' name='checkall' onclick='checkUncheckAll(this);'></span>
Final Decision: <select name='moderate'>
<option value='yes'>Accept</option>
<option value='no'>Decline</option>
</select> <input type='Submit' name='Submit3' value='apply'></div></div><br />
";


while ($thread = mysql_fetch_assoc($result)) {

$length = strlen($per[title]);

$cutted_desc = substr("$thread[desc]", 0, 300);

$shorttdesc = $cutted_title."...";
if ($length <= 301) {
$total_desc = $thread['desc'];
}else{
$total_desc = $thread['desc']."...";
}


echo " <div id='contentbox'>
<div class='hd'><span style='float:right;'><input type='checkbox' name='removeid[]' id='$thread[id]' value='$thread[id]'></span>Submitted Tool: $thread[title]</div>
<div class='cwrap'>
<table style='border:0;' cellpadding='5'>
<tr>
<td rowspan='6'><img src='http://$host/$thread[pic]'></td>
<td><b>Tool name:</b></td><td>$thread[title]</td></tr><tr>
<td><b>Tool website:</b></td><td><a href='$thread[site]' title='Opens in a new window.'>$thread[site]</a></td></tr><tr>
<td><b>Tool creator:</b></td><td>$thread[by]</td></tr><tr>
<td><b>Description:</b></td><td>$total_desc</td></tr>
</tr>
</table>

</div></div>
";

}

echo "</form><div style='padding:4px;text-align:right;margin-top:5px;' id='normal'>";

/****** build the pagination links ******/
// range of num links to show
$range = 3;
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
echo " <a href='?act=manage&currentpage=1'><img src='http://$host/icons/resultset_first.png' border='0'></a> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
echo " <a href='?act=manage&currentpage=$prevpage'><img src='http://$host/icons/resultset_previous.png' border='0'></a> ";
} // end if
// loop to show links to range of pages around current page
for ($x = (($currentpage - $range) - 1); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo " [<b>$x</b>] ";
// if not current page...
} else {
// make it a link
echo " <a href='?act=manage&currentpage=$x'>$x</a> ";
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
echo " <a href='?act=manage&currentpage=$nextpage'><img src='http://$host/icons/resultset_next.png' border='0'></a> ";
// echo forward link for lastpage
echo " <a href='?act=manage&currentpage=$totalpages'><img src='http://$host/icons/resultset_last.png' border='0'></a> ";
} // end if
echo "</div>";
/****** end build pagination links ******/




}else{
echo "<div id='error'>Invalid Permissions.</div>";
}

break;

}

include("includes/footer.php");
?>

What am I doing wrong?
I am trying to upload an image in tool submit case.

abduraooft
09-02-2009, 08:10 AM
<form action='tools.php?act=submit' method='post'> Make sure that your file is being uploaded before carrying any operation on it. Just dump the $_FILES array while development, like
echo '<pre>'; print_r($_FILES);echo '</pre>';

You need to have a enctype attribute applied on your <form> tag, for uploading a file. See http://www.w3.org/TR/html401/interact/forms.html#h-17.3



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum