xeirus Posted September 24, 2012 Share Posted September 24, 2012 Hi all! I'm going through a very strange problem. I have an identical code on BlueHost and GoDaddy. On BlueHost it does NOT work and on GoDaddy it works just fine. Both BlueHost and GoDaddy are using PHP v5.2.17 The code is: // Validating the Image (userfile) if (empty($userfile)) $errorArray['Image File'] = "Browse and select a GIF/JPEG Image File to upload!"; elseif (!($userfile_type =="image/pjpeg" OR $userfile_type=="image/gif")) $errorArray['Uploaded Image'] = "Your uploaded file must be either JPG or GIF only!"; elseif (!doesuserfile_nameEventBannerExist($userfile_name)) $errorArray['Uploaded Image'] = "Filename already Exists, Rename and Upload again!"; Please help ! Thank you Quote Link to comment https://forums.phpfreaks.com/topic/268734-userfile_type-and-userfile_name-not-working/ Share on other sites More sharing options...
Christian F. Posted September 24, 2012 Share Posted September 24, 2012 What do you mean with "not work"? We need specifics, otherwise we cannot help. If you get error messages, post them here. If you don't, make sure you've got error reporting turned on (or check the error logs). Also, please post more of your code, so that we can see exactly what happens prior to the problem. I recommend that you read this article. Quote Link to comment https://forums.phpfreaks.com/topic/268734-userfile_type-and-userfile_name-not-working/#findComment-1380529 Share on other sites More sharing options...
xeirus Posted September 24, 2012 Author Share Posted September 24, 2012 Hi Christian, Turned error reporting on and this is the error I'm getting: Notice: Undefined variable: userfile_type in /home6/user/public_html/eventbanner_uploader.php on line 70 Quote Link to comment https://forums.phpfreaks.com/topic/268734-userfile_type-and-userfile_name-not-working/#findComment-1380533 Share on other sites More sharing options...
kicken Posted September 24, 2012 Share Posted September 24, 2012 It sounds like GoDaddy has the register_globals directive enabled (which is a BAD thing) and you're relying on that. You should fix your scripts to not rely on this setting. In this particular case that means using the $_FILES superglobal to access your file upload details: if (empty($_FILES['userfile'])) $errorArray['Image File'] = "Browse and select a GIF/JPEG Image File to upload!"; elseif (!($_FILES['userfile']['type'] =="image/pjpeg" OR $_FILES['userfile']['type']=="image/gif")) $errorArray['Uploaded Image'] = "Your uploaded file must be either JPG or GIF only!"; elseif (!doesuserfile_nameEventBannerExist($_FILES['userfile']['name'])) $errorArray['Uploaded Image'] = "Filename already Exists, Rename and Upload again!"; Quote Link to comment https://forums.phpfreaks.com/topic/268734-userfile_type-and-userfile_name-not-working/#findComment-1380543 Share on other sites More sharing options...
xeirus Posted September 24, 2012 Author Share Posted September 24, 2012 Thanks Kicken. But doesn't work either. Any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/268734-userfile_type-and-userfile_name-not-working/#findComment-1380604 Share on other sites More sharing options...
PFMaBiSmAd Posted September 24, 2012 Share Posted September 24, 2012 Define: But doesn't work either. We are not standing right next to you and don't know what you saw in front of you. Quote Link to comment https://forums.phpfreaks.com/topic/268734-userfile_type-and-userfile_name-not-working/#findComment-1380608 Share on other sites More sharing options...
xeirus Posted September 24, 2012 Author Share Posted September 24, 2012 Define: But doesn't work either. We are not standing right next to you and don't know what you saw in front of you. Sorry, I meant that the modified code provided by kicken in post #4 does not work. I have error reporting turned fully on and there's no error. And the only validation error I get from the form is: Image File: Browse and select a GIF/JPEG Image File to upload! Quote Link to comment https://forums.phpfreaks.com/topic/268734-userfile_type-and-userfile_name-not-working/#findComment-1380611 Share on other sites More sharing options...
PFMaBiSmAd Posted September 25, 2012 Share Posted September 25, 2012 (edited) Assuming that nothing is going on in your form to make it invalid when moving between the different servers (such as a dynamically produced name='...' attribute that is empty), the $_FILES array can be empty due to - The total size of the form data exceeded the post_max_size setting. If uploads are not enabled. What does a phpinfo statement show for the post_max_size and file_uploads settings and what size of file did you try to upload? Edited September 25, 2012 by PFMaBiSmAd Quote Link to comment https://forums.phpfreaks.com/topic/268734-userfile_type-and-userfile_name-not-working/#findComment-1380751 Share on other sites More sharing options...
xeirus Posted September 25, 2012 Author Share Posted September 25, 2012 Assuming that nothing is going on in your form to make it invalid when moving between the different servers (such as a dynamically produced name='...' attribute that is empty), the $_FILES array can be empty due to - The total size of the form data exceeded the post_max_size setting. If uploads are not enabled. What does a phpinfo statement show for the post_max_size and file_uploads settings and what size of file did you try to upload? PFMaBiSmAd, Found out two issues, one was completely my fault, I forgot to put the following in the opening form tag: enctype="multipart/form-data" The only issue I'm stuck on is that when I use the following for my DocType, the upload does not work: <!DOCTYPE HTML> But if I use the following DocType, it works just fine: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> To answer your questions: post_max_size is set to 8M and I'm trying to upload a jpg image of about 200kb file_uploads are ON max_file_uploads is set to 20 Quote Link to comment https://forums.phpfreaks.com/topic/268734-userfile_type-and-userfile_name-not-working/#findComment-1380771 Share on other sites More sharing options...
PFMaBiSmAd Posted September 25, 2012 Share Posted September 25, 2012 I have an identical code on BlueHost and GoDaddy. On BlueHost it does NOT work and on GoDaddy it works just fine. I forgot to put the following in the opening form tag: enctype="multipart/form-data" So the code wasn't identical. As to the current problem, I'm not aware of the doctype affecting uploading. It's more likely you changed your form tag but didn't refresh the page to get the changes to take effect in the form already in the browser or you have some invalid HTML somewhere on the form page that is breaking the upload form or you tried a file that was too large or it didn't have a mime type that your code expected. Quote Link to comment https://forums.phpfreaks.com/topic/268734-userfile_type-and-userfile_name-not-working/#findComment-1380832 Share on other sites More sharing options...
xeirus Posted September 26, 2012 Author Share Posted September 26, 2012 So the code wasn't identical. As to the current problem, I'm not aware of the doctype affecting uploading. It's more likely you changed your form tag but didn't refresh the page to get the changes to take effect in the form already in the browser or you have some invalid HTML somewhere on the form page that is breaking the upload form or you tried a file that was too large or it didn't have a mime type that your code expected. Hi PFMaBiSmAd, Yes, just that multipart spot. Since then, I knew that I was losing things here and there so I have done a line by line check of the code. It is correct. The only difference is the DocType. Files I'm trying to upload are about 200kb (actually lesser, but not more). I'll keep trying and thanks for your help, I do appreciate every bit of it! Quote Link to comment https://forums.phpfreaks.com/topic/268734-userfile_type-and-userfile_name-not-working/#findComment-1380984 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.