johnseito Posted February 18, 2008 Share Posted February 18, 2008 I created a upload form to upload only a JPEG file type but it doesn't seem to work even if the file I upload is JPEG. Quote: if (($uploaded_type=="image/jpeg")) { anyone know what is wrong here? thanks Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 18, 2008 Share Posted February 18, 2008 there is also pjpeg. Try outputting the filetype, and see what it spits out. also your method should be <?php $allowed_type = array('image/gif','image/pjpeg','image/png','image/jpeg'); if(in_array($uploaded_type,$allowed_type)){ ?> Quote Link to comment Share on other sites More sharing options...
johnseito Posted February 19, 2008 Author Share Posted February 19, 2008 Yup, I changed it to how you have it and it still doesn't work. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 19, 2008 Share Posted February 19, 2008 Yup, I changed it to how you have it and it still doesn't work. Echo the filetype, and post where you defined $uploaded_type Quote Link to comment Share on other sites More sharing options...
johnseito Posted February 19, 2008 Author Share Posted February 19, 2008 Here is what I have. <?php if (isset($_POST['submit'])) { $target = "pictures/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; $allowed_type = array('image/jpg','image/tif','image/gif','image/pjpeg','image/png','image/jpeg'); if(in_array($uploaded_type,$allowed_type)){ if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "<font color =red> The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded</font><br><br>"; } else { echo "<font color=red> Sorry, there was a problem uploading your file. Please try again!</font><br><br>"; } }else { echo "<font color=red>Sorry, you may only upload JPEG files!</font><br><br>"; $ok=0; } } ?> <form enctype="multipart/form-data" action="upload.php" method="POST"> Please choose a file: <input name="uploaded" type="file" /><br /> <input type="submit" name="submit" value="Upload" /> </form> Quote Link to comment Share on other sites More sharing options...
johnseito Posted February 19, 2008 Author Share Posted February 19, 2008 Ok I noticed something. I was missing these codes.. sometimes example codes are never completed. $uploaded_type = $_FILES['uploaded']['type']; Quote Link to comment Share on other sites More sharing options...
johnseito Posted February 19, 2008 Author Share Posted February 19, 2008 But I do have a question if you know that would be great. I can only upload file size that are under 2mb, anything above that doesn't works. How can I do to change this, I changed the php ini to allow 300mb and it doesn't do any good. thanks Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 19, 2008 Share Posted February 19, 2008 ini_set('upload_max_filesize','300'); I think its that Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 19, 2008 Share Posted February 19, 2008 Try <?php ini_set('max_upload_size', '50M'); ?> change the value of 50M Quote Link to comment Share on other sites More sharing options...
johnseito Posted February 19, 2008 Author Share Posted February 19, 2008 No, it doesn't work. Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 19, 2008 Share Posted February 19, 2008 Relevant php.ini settings: file_uploads = on upload_max_filesize = 100M max_execution_time = 240 max_input_time = 240 memory_limit = -1 post_max_size = 100M hope this helps, Quote Link to comment Share on other sites More sharing options...
johnseito Posted February 19, 2008 Author Share Posted February 19, 2008 No, it doesn't work. any other ideas? Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 19, 2008 Share Posted February 19, 2008 try php_info(); see if you can find anything that prevents you from uploading larger files, also check it to make suer your editing the correct php.ini file (more often than not people have multiple copies of php.ini in the php bin/system32 folder/windows folder etc) other than that im not sure but maybe your web server (ie apache) is causing the problem. --- also, what operating system/php version/apache vers you running and what exactly happens when you try to upload files larger than 2mb? Quote Link to comment Share on other sites More sharing options...
johnseito Posted February 19, 2008 Author Share Posted February 19, 2008 I changed all the php.ini files to this file_uploads = on upload_max_filesize = 100M max_execution_time = 240 max_input_time = 240 memory_limit = -1 post_max_size = 100M and it still doesn't work what operating system/php version/apache vers you running and what exactly happens when you try to upload files larger than 2mb? Operating system ---- vista php version --------- PHP 5.2.3 apache version - -----http server 2.2.4 It just doesn't upload it, it pretty much gives me an error, because in my code if it doesn't do this if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) it will give me an error. When it upload successfully I will not see the error and I can see the file uploaded in the directory. Quote Link to comment Share on other sites More sharing options...
priti Posted February 19, 2008 Share Posted February 19, 2008 your form - post size should also be more. to increase it use php.ini and set post_max_size. upload_max_filesize = 10M ; post_max_size = 20M ; and remember to check your memory_limit notable point is :memory_limit should be larger than post_max_size Regards Quote Link to comment Share on other sites More sharing options...
johnseito Posted February 19, 2008 Author Share Posted February 19, 2008 I did that, it didn't work. Quote Link to comment Share on other sites More sharing options...
priti Posted February 19, 2008 Share Posted February 19, 2008 What is the size of your file???? and which error are you receiving? Quote Link to comment Share on other sites More sharing options...
johnseito Posted February 20, 2008 Author Share Posted February 20, 2008 uniflare other than that im not sure but maybe your web server (ie apache) is causing the problem. Does it work for you? you talked as if you have it done Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 20, 2008 Share Posted February 20, 2008 no im sorry ive never attempted to up the limit on upload sizes, ive just read a lot of posts on other forums in similar situations. sorry Quote Link to comment Share on other sites More sharing options...
yzerman Posted February 20, 2008 Share Posted February 20, 2008 try this - its untested, and incomplete, but it should get you on the right track: <?php //check that there were no errors, and that something was submitted if(!empty($_FILES) && $_FILES['attachment']['error'] == 0) { //['attachment'] is the name you gave your file input box //no errors, and a file is present - assign and check the values: $file_name = $_FILES['attachment']['name']; $file_type = $_FILES['attachment']['type']; $file_size = $_FILES['attachment']['size']; $file_tmpname = $_FILES['attachment']['tmp_name']; $error = array(); //set allowed file types and check against the uploaded file $allowed_types = array('image/jpeg','image/pjpg','image/png','image/gif'); if(!in_array($allowed_types, $file_type)) { //not an allowed file type $error .= 'type'; } //next set the max filesize and check it against your file. 1048576 bytes = 1 mb $max_size = 1048576; if($max_size < $file_size) { //if the file is larger then the max size allowed: $error .= 'size'; } //and so on.... //File checking done, lets see if there were any errors: if(!empty($error)) { //there was an error //some code here explaining what the errors were and output to the user } else { //no errors //upload the file } } //fin ?> Quote Link to comment 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.