supanoob Posted March 16, 2007 Share Posted March 16, 2007 i have the following bit of code for uploading images of a certain Dimension and type but it keeps throwing the invalid file type error whenever someone uploads anything other than a bmp file. <?php if ($_GET['step'] == 'upload_new_complete') { // Your file name you are uploading $file_name = $HTTP_POST_FILES['ufile']['name']; if ($HTTP_POST_FILES['ufile']['type'] == 'image/gif' || $HTTP_POST_FILES['ufile']['type'] == 'image/jpeg' || $HTTP_POST_FILES['ufile']['type'] == 'image/jpg' || $HTTP_POST_FILES['ufile']['type'] == 'image/bmp') { //check make sure they are allowed more images if ($current_images > $max_images) { echo "You cannot hold any more images. Please [delete] Some."; DIE(include_once('logged_in_bottom.php')); } //find out what the file extension will be if ($HTTP_POST_FILES['ufile']['type'] == 'image/gif') { $type="gif"; } if ($HTTP_POST_FILES['ufile']['type'] == 'image/jpg') { $type="jpg"; } if ($HTTP_POST_FILES['ufile']['type'] == 'image/jpeg') { $type="jpeg"; } if ($HTTP_POST_FILES['ufile']['type'] == 'image/bmp') { $type="bmp"; } //assign the extension and new name. $new_file_name=("$images_had"."$account_id".".$type"); //set where you want to store files //in this example we keep file in folder upload //$new_file_name = new upload file name //for example upload file name cartoon.gif . $path will be upload/cartoon.gif $path= "/home/porky/public_html/profile/".$new_file_name; if($ufile !=none) { if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path)) { $new_file_name=("$images_had"."$account_id".".$type"); //get the dimensions list($width, $height, $attr) = getimagesize("profile/$new_file_name"); //if they are too big kill the upload. if ($width > 365 || $hieght > 365) { echo "The Image dimensions are too big. Please make sure it is no bigger than 365x365"; unlink("profile/$new_file_name"); DIE(include_once('logged_in_bottom.php')); } echo "Upload Successful<BR/>"; if ($profile_image == '') { $new_file_name=("$images_had"."$account_id".".$type"); $sql2="UPDATE tord_accounts SET profile_image='$new_file_name' WHERE account_id='$account_id'"; if(mysql_query($sql2)); } $sql2="UPDATE tord_accounts SET current_images=current_images+1 WHERE account_id='$account_id'"; if(mysql_query($sql2)) $new_file_name=("$images_had"."$account_id".".$type"); $query="insert into tord_images (whos_image, image_name, image_type) values ('$account_id', '$new_file_name', 'Profile')"; $result=mysql_query($query); $sql2="UPDATE tord_accounts SET images_had=images_had+1 WHERE account_id='$account_id'"; if(mysql_query($sql2)) //echo the results echo "<a href=\"account.php?step=images\">Click Here to View</a><br>"; echo "Image Thumbnail:<br> <img src=\"/profile/$new_file_name\" width=\"150\" height=\"150\">"; } else { echo "Error"; } } } else { echo "That is an invalid File Type. Please make sure you upload a .jpeg .jpg .gif .bmp"; } ?> any help will be much appreciated. Link to comment https://forums.phpfreaks.com/topic/43003-uploading-problem/ Share on other sites More sharing options...
per1os Posted March 16, 2007 Share Posted March 16, 2007 Change $HTTP_POST_FILES to $_FILES, I think $HTTP_POST_FILES is being or has been depreciated for some time. Link to comment https://forums.phpfreaks.com/topic/43003-uploading-problem/#findComment-208859 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.