Jump to content

Upload script not working?


L

Recommended Posts

Hey,

I have been using this for a while, but I noticed that it's been breaking down lately. for instance, when I select an image to upload it gives me an error"No image selected" even though one was.

The script is kind of long so I'm sorry if you have to read through all of it...but I'll mark it up for you.

  if(isset($_POST['submit'])) {
list($width, $height) = getimagesize($_FILES['userphoto']['tmp_name']);
mysql_select_db('iffatb_ayase', $conn1);
$yah = mysql_query("SELECT * FROM `posts` WHERE `by`='".$_SESSION['userid']."' and `subtopsid`!='16'", $conn1);
////Dif. post/rep give you different rights so this is where I differ between the two.
if (mysql_num_rows($yah) >= 200 || $touser['stafflevel'] > 0 || $touser['rep'] >= 400) {
$maxwidth = 151;
$maxheight = 151;
   $maxfilesize = 300000;
   } else {
   $maxwidth = 100;
$maxheight = 100;
   $maxfilesize = 50000;
   }
$ext = strrchr($_FILES['userphoto']['name'], ".");
// check if there was a file uploaded
if (!is_uploaded_file($_FILES['userphoto']['tmp_name'])) {
    $error = "you didn't select a file to upload.<br /><br />";
// if it was, go ahead with other checks
} else if ($_FILES['userphoto']['size'] > $maxfilesize) {
        $error = "your image file was too large.<br /><br />";
        unlink($_FILES['userphoto']['tmp_name']);
    } elseif 
        
        ($ext != ".bmp" AND $ext != ".gif" AND $ext != ".jpg" AND $ext != ".jpeg" AND $ext != ".GIF" AND $ext != ".JPG" AND $ext != ".JPEG" AND $ext != ".BMP" AND $ext != ".png" AND $ext != ".PNG") {
            $error = "your file was an unacceptable type.<br /><br />";
            unlink($_FILES['userphoto']['tmp_name']);
        }
        elseif ($height > $maxheight || $width > $maxwidth) {
$error = "your image file was too large. <br />";
unlink($_FILES['userphoto']['tmp_name']);
}  
		else
        {
        $_SESSION['photo'] = $newname;
            $newname = $_SESSION['userid'].$ext;
            move_uploaded_file($_FILES['userphoto']['tmp_name'],"avatar/".$newname);
            mysql_select_db('iffatb_riaz', $conn);
// if it's there, an okay size and type, copy to server and update the photo value in SQL
            mysql_query("UPDATE users SET photo='$newname' WHERE userid='".$_SESSION['userid']."''") or die (mysql_error());
            
        }
   if ($error) {
echo "<b>Change Photo Result</b><br />";
    echo "Your photo could not be changed because ".$error."";
} else {
echo "<b>Change Photo Result</b>";
echo "Your photo was successfully uploaded.<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"2; URL=/memberscript/account.php\">";
}
}
?>

 

Sorry for the long code, but I can't figure out why this isn't working...I think it might be outdated?

Thank you for your time

~L

Link to comment
https://forums.phpfreaks.com/topic/84631-upload-script-not-working/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.