webmistress Posted September 14, 2006 Share Posted September 14, 2006 this bit of code has me spinning.....i'm attempting to upload a CORRECT file type..from the research i've done i think theres something written wrong in the code below.here is the error i get:Warning: array_search(): Wrong datatype for second argument in /home/****/public_html/admincp/upload2.php on line 35Invalid image file type!this is the code:{ if (array_search(strtolower(substr($file['name'],strrpos($file['name'], '.')+1)), $config['ftypes']) == false) { echo "<B>Invalid image file type!</B>"; exit; }Please help.......... :) Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted September 14, 2006 Share Posted September 14, 2006 The array_search() function requires that the second parameter is an array. What is in the variable $config['ftypes']?Ken Quote Link to comment Share on other sites More sharing options...
onlyican Posted September 14, 2006 Share Posted September 14, 2006 Did you check the array_search function information on phparray_search() Argument Requirmentsarray_seach('Value', $array);You seem to have array value ($config['ftypes'];What I would do is something like this[code]<?php$value = strtolower(substr($file['name'], strrpos($file['name'], '.')+1));if(array_search($value, $config) == false){echo "<strong>Invalid Image File Type!</strong>";exit;}?>[/code]alsoisn't file meant to be$_FILES["filedname"]["name"];//Where fieldname is the name of the field in the upload formAndremember that the file extension can be manually changed.For Examplea image.bmp could be changed to image.jpgbut the image is still a bitmap (bmp)To get the actual typeuse[code]<?phplist($width, $hieght, $type) = getimagesize($_FILES["fieldname"]["name"];//Where filedname is the name of the field from the upload form, name is the same $types = array(1 => 'gif', 2 => 'jpg', 3 => 'png', 4 => 'SWF', 5 => 'PSD', 6 => 'BMP', 7 => 'TIFF(intel byte order)', 8 => 'TIFF(motorola byte order)', 9 => 'JPC', 10 => 'JP2', 11 => 'JPX', 12 => 'JB2', 13 => 'SWC', 14 => 'IFF', 15 => 'WBMP', 16 => 'XBM');$file_ext = $types[$type];?>[/code] Quote Link to comment Share on other sites More sharing options...
webmistress Posted September 14, 2006 Author Share Posted September 14, 2006 The 'ftypes' are in the config.php fileas seen below..this is what is in the config.php$config['ftypes'] = array('jpg','jpeg','png','gif','bmp');*p.s. I didn't write this program I'm just trying to fix it because the person who did write it left in a ton of bugs! Quote Link to comment Share on other sites More sharing options...
webmistress Posted September 14, 2006 Author Share Posted September 14, 2006 [color=red]Here is the upload form:[/color][b]<form name="upload" method="post" action="admincp.php?id=upload2" enctype="multipart/form-data"><input type="hidden" name="type" value="1142565325"><input type="hidden" name="codes" value="1"><input type="hidden" name="typestr" value="myspace">Type: myspace<BR><BR>Category: <select name="category"><option value="1142565028">Layouts</option><option value="1142632578">Backgrounds</option><option value="1142860707">Glitter</option><option value="1142860728">Contact Tables</option><option value="1142860769">Dolls</option><option value="1142860774">Welcome</option><option value="1142894168">Thanks For The Add</option><option value="1158181685">Online Now</option></select><BR><BR>150x150 Thumbnail: <input type="file" name="file"><br>Name: <input type="text" name="name"><BR><BR>Description:<br><textarea name="description" cols=25 rows=5></textarea><br><BR>CODES:<BR><BR>code:<br><textarea name="code1" cols=50 rows=10></textarea><br><br><input type="submit" name="submit" value="Add Layout"></form>[/b] Quote Link to comment Share on other sites More sharing options...
webmistress Posted September 14, 2006 Author Share Posted September 14, 2006 [code]<?php$value = strtolower(substr($file['name'], strrpos($file['name'], '.')+1));if(array_search($value, $config) == false){echo "<strong>Invalid Image File Type!</strong>";exit;}?>[/code]I tried the above mentioned and now that error is gone & I begin getting parse errors from further down in the code which I believe are being effected by this fix....is this possible? Quote Link to comment Share on other sites More sharing options...
onlyican Posted September 14, 2006 Share Posted September 14, 2006 probs, I typed that code quickly out of memoryShow us the line of the parse error Quote Link to comment Share on other sites More sharing options...
webmistress Posted September 14, 2006 Author Share Posted September 14, 2006 [code]<table width="70%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><? include("include.php"); chdir("..");?><?if (!isset($_COOKIE['mys_admin'])) { exit;}if (!isset($_COOKIE['mys_pass'])) { exit;}function getname($thename) { global $mysql_server,$mysql_user,$mysql_pass,$mysql_db; mysql_connect($mysql_server,$mysql_user,$mysql_pass); mysql_select_db($mysql_db); $tmpquery = mysql_query("SELECT * FROM `approved` WHERE LOWER(`name`) = '".strtolower($thename)."'"); $tmpresult = @mysql_fetch_array($query); mysql_close(); return empty($tmpresult);}if (isset($submit)) { if ($name == "") { echo "<b>Your template must have a name!" ; exit ; } if ($description == "") { echo "<b>Your template must have a description!" ; exit ; } if (empty($file)) { echo "<b>You must upload a 150x150 thumbnail with your code!" ; exit ; } $count = 1; $old_name = $name; $alias = ereg_replace("[^[:space:]a-zA-Z0-9*_.-]", "", $name); $alias = str_replace(" ","-",strtolower($alias)); $typestr = ereg_replace("[^[:space:]a-zA-Z0-9*_.-]", "", $typestr); $typestr = str_replace(" ","-",strtolower($typestr)); foreach ($_FILES as $file) { if (array_search(strtolower(substr($file['name'],strrpos($file['name'], '.')+1)), $config['ftypes']) == false) { echo "<B>Invalid image file type!</B>"; exit; } $ext = strtolower(substr($file['name'], strrpos($file['name'], '.')+1)); if (move_uploaded_file($file['tmp_name'], $script_dir . "thumbs/" . $typestr . "_layout_" . $alias . "." . $ext)) { mysql_connect($mysql_server,$mysql_user,$mysql_pass); mysql_select_db($mysql_db); $time = time(); mysql_query("INSERT INTO `pending` VALUES('".$time."','".addslashes($name)."','".addslashes($description)."','".$type."','".$category."','".strtolower($_COOKIE['mys_admin'])."','".$alias."','". $typestr . "_layout_" . $alias . "." . $ext."')"); $code[0] = ""; $temp = 1; while ($temp <= 10) { if (isset($_POST['code'.$temp])) { $code[$temp] = addslashes($_POST['code'.$temp]); } else { $code[$temp] = ""; } $temp = $temp + 1; } mysql_query("INSERT INTO `codes` VALUES('".$time."','".$code[1]."','".$code[2]."','".$code[3]."','".$code[4]."','".$code[5]."','".$code[6]."','".$code[7]."','".$code[8]."','".$code[9]."','".$code[10]."')"); mysql_close(); } else { echo '<b>Thumbnail upload failed! Please contact site admin.</b><br>'; } } echo "<B>Your layout addition is currently pending. Note all pending layouts will not be published on our site until admin approval.</B><BR><BR>";}?><B>UPLOAD LAYOUT</B><BR><form name="upload" method="post" action="admincp.php?id=upload2" enctype="multipart/form-data"><?$type = explode("_",$type);$type[1] = str_replace(" ","-",strtolower($type[1]));?><input type="hidden" name="type" value="<?=$type[0]?>"><input type="hidden" name="codes" value="<?=$type[2]?>"><input type="hidden" name="typestr" value="<?=$type[1]?>">Type: <?=$type[1]?><BR><BR>Category: <select name="category"><?mysql_connect($mysql_server,$mysql_user,$mysql_pass);mysql_select_db($mysql_db);$query = mysql_query("SELECT * FROM `categories`");while ($result = mysql_fetch_assoc($query)) { echo '<option value="'.$result["id"].'">'.$result["name"].'</option>';}mysql_close();?></select><BR><BR>150x150 Thumbnail: <input type="file" name="file"><br>Name: <input type="text" name="name"><BR><BR>Description:<br><textarea name="description" cols=25 rows=5></textarea><br><BR>CODES:<BR><BR><?mysql_connect($mysql_server,$mysql_user,$mysql_pass);mysql_select_db($mysql_db);$query = mysql_query("SELECT * FROM `code_names` WHERE `id` = '".$type[0]."' LIMIT 1");$result = mysql_fetch_array($query);$temp = 1;while ($temp <= $type[2]) { $str = "code".$temp; echo $result[$str].":<br>"; echo '<textarea name="code'.$temp.'" cols=50 rows=10></textarea><br><br>'; $temp = $temp + 1;}mysql_close();?><input type="submit" name="submit" value="Add Layout"></form> </td> </tr></table>[/code]that is the entire file......... THANKS!!!!!!!!!!!!! It gave parse errors in the line 58 area Quote Link to comment Share on other sites More sharing options...
onlyican Posted September 14, 2006 Share Posted September 14, 2006 THere is no Parse Error on that code Quote Link to comment Share on other sites More sharing options...
webmistress Posted September 15, 2006 Author Share Posted September 15, 2006 when using the following piece of code i get the following error:Parse error: syntax error, unexpected '}' in /home/***/public_html/admincp/upload2.php on line 63[code]$value = strtolower(substr($file['name'], strrpos($file['name'], '.')+1));if(array_search($value, $config) == false){echo "<strong>Invalid Image File Type!</strong>";exit;}[/code] Quote Link to comment Share on other sites More sharing options...
btherl Posted September 15, 2006 Share Posted September 15, 2006 There's no parse errors in that code snippet, or in the full code you posted earlier.. which leaves three alternatives (that I can think of)1. There's a syntax error in your current version of the file, but it occurs before or after the location it's reported. This is often due to mismatched { and }2. There's a syntax error in a file included by your file (in include.php ?)2. You didn't save the file before testing (I have spent HOURS trying to fix bugs only to find I didn't save the file :D ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.