Jump to content


File upload problem


1 reply to this topic

#1 Friiks

    Young Padawan

  • Members
  • Pip
  • 56 posts
  • Gender:Male
  • Location:Latvia
  • Interests:Guitar, music, having all sorts of fun...and well enjoying my life (as enjoyable as it can be) as good as I can :D<br /><br />Oh yea, and of course - http://snowmoons.com

Posted 03 February 2007 - 11:18 AM

Well, no questions I have except for this - could anyone tell me whats wrong with my code?
<?php
session_start();
include 'config.php';
$photo=$_POST['pic'];
$file = $_FILES['userfile']['tmp_name'];
$valid = array (".png",".jpg",".jpeg",".gif",".ico",".tif");
////////////////////////////////////////
$nameext= $_FILES['userfile']['name'];
$ext = strtolower(strrchr($nameext, "."));
$namei=$_SESSION['username'].$ext;
////////////////////////////////////////
if ($photo=='avatar'){
$path='images/avatars/'.$namei;}
elseif ($photo=='propic'){
$path='images/photos/'.$namei;}

$image_dimensions = getimagesize($file);
$height = $image_dimensions[1];
$width = $image_dimensions[0];

if ($photo=='avatar'){

if (in_array($ext, $valid){
if (($width>64) || ($height>64)){
$text='Image dimensions are too big';
header('Location: index.php?i=avatar');
}else{
if(copy($file, $path))
{
mysql_query("UPDATE `users` SET avatar='".$path."' WHERE id='".$_SESSION['id']."'");
header('Location: index.php?i=usrinfo&id='.$_SESSION["id"].'');
}
else{
header('Location: index.php?i=avatar');
}
}
else{
header('Location: index.php?i=avatar');
}
}

}

if ($photo=='photo'){

if (in_array($ext, $valid){
if (($width>175) || ($height>200)){
header('Location: index.php?i=avatar');
}else{
if(copy($file, $path))
{
mysql_query("UPDATE `users` SET avatar='".$path."' WHERE id='".$_SESSION['id']."'");
header('Location: index.php?i=usrinfo&id='.$_SESSION["id"].'');
}
else{
header('Location: index.php?i=avatar');
}
}
else{
header('Location: index.php?i=avatar');
}
}

}
?>

And here's the form
<form action="avaup.php" method="POST" enctype="multipart/form-data">
Select a file <input type="file" name="userfile" size="18"><br>
<select name='pic' class='select'>
<option value='avatar'>Avatar</option>
<option value='propic'>Profile picture</option>
</select><br>
<input type='submit' name='submit' value='Submit'>
</form>
When I submit the form it just gives me a blank page..so I just don't know whats wrong with it =/

Thanks, Matt.

#2 LkuHomer

    Young Padawan

  • Members
  • Pip
  • 173 posts
  • Gender:Male
  • Location:Dela'where?

Posted 03 February 2007 - 01:23 PM

if (in_array($ext, $valid){
Missing a bracket
if (in_array($ext, $valid)){

You also have too many else statements that do the same things as the first argument in the if statements.

And one more thing to keep in mind, please please please clean up your code. And stick with one way of coding.
example:
if (arguement){

and

if(arguement)
{
Makes it kind of hard and takes longer to troubleshoot.

Edited by LkuHomer, 03 February 2007 - 01:34 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users