SieRobin Posted July 11, 2006 Share Posted July 11, 2006 Anyone find anything wrong with this array? The script isn't doing it what I ask it to, was before but now it just magically doesn't work.$extension=array('image/gif', 'image/pjpeg', 'image/x-png'); Quote Link to comment https://forums.phpfreaks.com/topic/14251-array-help/ Share on other sites More sharing options...
Prismatic Posted July 11, 2006 Share Posted July 11, 2006 Post your code pleaseand use the Code tags when you do :P Quote Link to comment https://forums.phpfreaks.com/topic/14251-array-help/#findComment-55953 Share on other sites More sharing options...
SieRobin Posted July 11, 2006 Author Share Posted July 11, 2006 My code is very jumbled.. what it is, is a picture upload script, it worked great before but now it's doing what it did before.. instead of putting the extension at the end of the picture name, it puts "array". I modified the script to output the users ID number and the extension. Like I said, it worked before, but now it doesn't.. and I never altered the code after it did actually work. So my user ID number is 1 therefore if the picture I uploaded was a jpg it would read as 1.jpg. You asked for the code, don't expect amazement lol. Quote Link to comment https://forums.phpfreaks.com/topic/14251-array-help/#findComment-55954 Share on other sites More sharing options...
SieRobin Posted July 11, 2006 Author Share Posted July 11, 2006 [code] $player=$_SESSION['player']; $userstats="select * from users where playername='$player'"; $userstats2=mysql_query($userstats) or die("Could not query players"); $userstats3=mysql_fetch_array($userstats2); if($_POST['upload']) { if($_FILES['image']['name'] == "") { echo "<table class='table' align='center'><tr class='headline'><td><center>Upload Image</center></td></tr> <tr class='mainrow'><td><center>Please select a file to upload!<br> [<a href='settings.php'>Settings</a>]</center></td></tr></table>"; exit; } $extension=array('image/gif', 'image/pjpeg', 'image/x-png'); $file="userimages/$userstats3[ID]$extension"; if(!in_array($_FILES['image']['type'], $extension)) { echo "<table class='table' align='center'><tr class='headline'><td><center>Upload Image</center></td></tr> <tr class='mainrow'><td><center>That file type is not allowed!<br> [<a href='settings.php'>Settings</a>]</center></td></tr></table>"; exit; } $max_filesize = 102400; $max_filesize_kb = ($max_filesize / 1024); if($_FILES['image']['size'] > $max_filesize) { echo "<table class='table' align='center'><tr class='headline'><td><center>Upload Image</center></td></tr> <tr class='mainrow'><td><center>Your file is too large, files may be up to $max_filesize_kb kb.<br> [<a href='settings.php'>Settings</a>]</center></td></tr></table>"; exit; } $imagesize = getimagesize($_FILES['image']['tmp_name']); $imagewidth = $imagesize[0]; $imageheight = $imagesize[1]; $maxwidth = 500; $maxheight = 500; if($imagewidth > $maxwidth || $imageheight > $maxheight) { echo "<table class='table' align='center'><tr class='headline'><td><center>Upload Image</center></td></tr> <tr class='mainrow'><td><center>Your file is too large, files may be up to $maxwidth px x $maxheight px in size.<br> [<a href='settings.php'>Settings</a>]</center></td></tr></table>"; exit; } if ($userstats3['uimage']=="") { move_uploaded_file($_FILES['image']['tmp_name'], $file) or die ("Couldn't upload ".$_FILES['image']['name']."\n"); mysql_query("UPDATE users set uimage='$file' where ID='$userstats3[ID]'"); echo "<table class='table' align='center'><tr class='headline'><td><center>Upload Image</center></td></tr> <tr class='mainrow'><td><center>Your image has been successfully uploaded.<br> [<a href='settings.php'>Settings</a>]</center></td></tr></table>"; exit; } else { echo "<table class='table' align='center'><tr class='headline'><td><center>Upload Image</center></td></tr> <tr class='mainrow'><td><center>You already have an image uploaded, delete your current image if you'd like a new image.<br> [<a href='settings.php'>Settings</a>]</center></td></tr></table>"; exit; } } [/code] Quote Link to comment https://forums.phpfreaks.com/topic/14251-array-help/#findComment-55955 Share on other sites More sharing options...
SieRobin Posted July 11, 2006 Author Share Posted July 11, 2006 No one eh? K thanks. Quote Link to comment https://forums.phpfreaks.com/topic/14251-array-help/#findComment-56427 Share on other sites More sharing options...
akitchin Posted July 11, 2006 Share Posted July 11, 2006 the reason is exactly as it says - $extension is an array, as you can see in the line you were asking about. to get the right extension, you'd have to figure out what the file's extension is, most likely with strrchr:[code]$real_extension = strrchr($filename, '.');[/code]and replace $extension with $real_extension when you define $file. note that you'll also have to replace $filename with whatever contains the file's actual name. Quote Link to comment https://forums.phpfreaks.com/topic/14251-array-help/#findComment-56432 Share on other sites More sharing options...
SieRobin Posted July 11, 2006 Author Share Posted July 11, 2006 Ok, so what I have to do is replace $extension with $real_extension when I define $file, but what exactly do I do with extension? Quote Link to comment https://forums.phpfreaks.com/topic/14251-array-help/#findComment-56437 Share on other sites More sharing options...
SieRobin Posted July 11, 2006 Author Share Posted July 11, 2006 I think I've got it :] thank you Quote Link to comment https://forums.phpfreaks.com/topic/14251-array-help/#findComment-56445 Share on other sites More sharing options...
akitchin Posted July 11, 2006 Share Posted July 11, 2006 no problem.for the record, $extension is the array of file types you deem acceptable, and is used in the if() immediately following $file's definition. Quote Link to comment https://forums.phpfreaks.com/topic/14251-array-help/#findComment-56446 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.