The14thGOD Posted January 28, 2007 Share Posted January 28, 2007 Hey, I've been working on my site pretty hardcore the last couple of days and I'm working on an Avatar upload. The code for uploading the image works fine but as soon as I tried to determine if the image was a valid size the script freezes up and still adds to by database even if it's an invalid size. Here's the code:[code]<?php import_request_variables('pq'); if ($disagree) { $error = 'disagree'; header("Location: login.php?error=$error"); exit(0); } if($password != $confirm_password) { $error = 'pass'; header("Location: login.php?error=$error"); exit(0); } if($email != $confirm_email) { $error = 'email'; header("Location: login.php?error=$error"); exit(0); } include("includes/include_connect_db.php"); //Cycle through to see if username is duplicate $query = "SELECT username FROM user "; $results = mysql_query($query); while($row = mysql_fetch_array($results)) { if ($username == $row[username]) { $error = 'user'; header("Location: login.php?error=$error"); exit(0); } } include("includes/include_random_gen.php"); $rand_id = get_rand_id(32); //First check that file ext = .jpg then rename file and location, also upload to perminate location $size = getimagesize($_FILES['avatar']['name']); if($size[0] == 82 and $size[1] == 82) { $size_true = 'true'; $extension = explode('.',$_FILES['avatar']['name']); if ($extension[1] == 'jpg') { $uploaddir = 'images/users/'; $select = "SELECT id FROM user ORDER BY id DESC LIMIT 1"; $sel_results = mysql_query($select); $sel_row = mysql_fetch_array($sel_results); $file_id = $sel_row[id] + 1; $filename = $file_id . '_' . $_FILES['avatar']['name']; $file_dir = "$uploaddir" . "$filename"; } } elseif ($extension[1] !== 'jpg' or !$size_true) { $error = 'file'; header("Location: login.php?error=$error&$size[0]"); exit(0); } //User Passed Tests, Do this (code removed)?>[/code]I've looked on PHP.net but get confused on that, and the book that I have doesnt really cover image width/height with the function getimagesize(). Also if anyone could help me with the MYSQL query of [code]<?php $select = "SELECT id FROM user ORDER BY id DESC LIMIT 1";?>[/code] I want it to select the next autoindex rather than id because if I delete a row then it selects the wrong id.Thanks in advance for any help. Link to comment https://forums.phpfreaks.com/topic/36014-solved-getimagesize-problem/ Share on other sites More sharing options...
The14thGOD Posted January 28, 2007 Author Share Posted January 28, 2007 Solved, I messed around and got it to work. Link to comment https://forums.phpfreaks.com/topic/36014-solved-getimagesize-problem/#findComment-170919 Share on other sites More sharing options...
trq Posted January 28, 2007 Share Posted January 28, 2007 PS: You really ought to be using getimagesize to find the file type aswell. Using the file extension is no guarentee.[code=php:0]if ($size[2] == 2) { // is jpeg}[/code] Link to comment https://forums.phpfreaks.com/topic/36014-solved-getimagesize-problem/#findComment-170921 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.