riceje7 Posted August 26, 2009 Share Posted August 26, 2009 hey i'm having a problem uploading image files in a simple registration form i'm making. it seems, as far as i can tell, that the form data for $_POST['image'] is not being passed through and is causing my script to fail at the mime type check. any ideas? here is the corresponding code: <?php $username = $_POST['username']; $password = $_POST['password']; $password = md5($password); $email = $_POST['email']; $zip = $_POST['zip']; $image = $_FILES['image']; $imagename = $_FILES['image']['name']; $imagename = str_replace(' ', '_', $imagename); echo $imagename; if(isset($username)) { $connect = mysql_connect(localhost, $user, $pass); $db = mysql_select_db(user_data); $sql = "SELECT * FROM user_data WHERE username='$username'"; $result = mysql_query($sql); $num = mysql_num_rows($result); //echo $num; if($num == 0) { $sql = "INSERT INTO `user_data`.`user_data` (`id`, `username`, `password`, `email`, `zipcode`, `picture_name`) VALUES (NULL, '$username', '$password', '$email','$zip', '$imagename');"; mysql_query($sql); echo "<center>Registration Successful</center>"; } else { echo "<center>Username Already Taken.</center>"; } $imageinfo = getimagesize($image); if($imageinfo['mime'] != 'image/gif' && $imageinfo['mime'] != 'image/jpeg' && $imageinfo['mime'] != 'image/jpe' && $imageinfo['mime'] != 'image/jpg') { echo "That is an invalid file type, you must upload either a JPEG or GIF file.\n Please use your browser's 'Back' button and try again.\n"; exit; } $uploaddir = "user_images/"; $uploadfile = $uploaddir.basename($imagename); if (move_uploaded_file($image, $uploadfile)) { echo "File Upload Successful.\n";} } ?> <html> <head> <link REL="SHORTCUT ICON" HREF="favicon.ico"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form name="form1" method="post" action="register.php"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td colspan="3" align="center"><strong>Member Registration </strong></td> </tr> <tr> <td width="78">Username</td> <td width="6">:</td> <td width="294"><input name="username" type="text" id="username"></td> </tr> <tr> <td>Password</td> <td>:</td> <td><input name="password" type="password" id="password"></td> </tr> <tr> <td>Email</td> <td>:</td> <td><input name="email" type="text" id="email"></td> </tr> <tr> <td>Zipcode</td> <td>:</td> <td><input name="zip" type="text" id="zip"></td> </tr> <tr> <td>Image</td> <td>:</td> <td><input name="image" type="file" id="image"></td> </tr> <tr> <td> </td> <td> </td> <td align="right"><input type="submit" name="Submit" value="Register"></td> </tr> </table> </td> </form> </tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/171918-solved-data-not-passing-through-_posti-think/ Share on other sites More sharing options...
MasterACE14 Posted August 26, 2009 Share Posted August 26, 2009 I don't see $_POST['image'] anywhere? Quote Link to comment https://forums.phpfreaks.com/topic/171918-solved-data-not-passing-through-_posti-think/#findComment-906516 Share on other sites More sharing options...
kickstart Posted August 26, 2009 Share Posted August 26, 2009 Hi Think you are trying to pass the array for that image, rather than the tmpname giving where it is stored on upload. Try $imageinfo = getimagesize($image['tmp_name']); All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/171918-solved-data-not-passing-through-_posti-think/#findComment-906518 Share on other sites More sharing options...
PravinS Posted August 26, 2009 Share Posted August 26, 2009 You need to use enctype="multipart/form-data" for your form tag like this <form name="form1" method="post" action="register.php" enctype="multipart/form-data"> Quote Link to comment https://forums.phpfreaks.com/topic/171918-solved-data-not-passing-through-_posti-think/#findComment-906528 Share on other sites More sharing options...
riceje7 Posted August 26, 2009 Author Share Posted August 26, 2009 i needed to fix both things you two pointed out. thanks so much for the help. Quote Link to comment https://forums.phpfreaks.com/topic/171918-solved-data-not-passing-through-_posti-think/#findComment-906584 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.