joequah1 Posted December 19, 2011 Share Posted December 19, 2011 Hi, My $_FILES is not working. Its working when Im doing my project on the local host. After I uploaded my project to the server, the $_FILES is not working. Im trying to upload images. the $_FILES['name'] couldn't read anything. its like no file there. whats causes it? any other way to read from <input type='file'/> ? or way to solve this? Thank You. Quote Link to comment https://forums.phpfreaks.com/topic/253459-_files-not-working/ Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 Can you do echo '<pre>' . print_r($_FILES, true) . '</pre>'; and post back what it outputs? This must be called after submitting the form. Also, are you using enctype="multipart/form-data" in your <form>? Quote Link to comment https://forums.phpfreaks.com/topic/253459-_files-not-working/#findComment-1299192 Share on other sites More sharing options...
joequah1 Posted December 19, 2011 Author Share Posted December 19, 2011 Can you do echo '<pre>' . print_r($_FILES, true) . '</pre>'; and post back what it outputs? This must be called after submitting the form. Also, are you using enctype="multipart/form-data" in your <form>? this is what i get Array ( ) Quote Link to comment https://forums.phpfreaks.com/topic/253459-_files-not-working/#findComment-1299231 Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 Did you use enctype="multipart/form-data" in your <form> tag? Quote Link to comment https://forums.phpfreaks.com/topic/253459-_files-not-working/#findComment-1299236 Share on other sites More sharing options...
joequah1 Posted December 19, 2011 Author Share Posted December 19, 2011 got. It works in the local but not at the server. Quote Link to comment https://forums.phpfreaks.com/topic/253459-_files-not-working/#findComment-1299240 Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 Are you exceeding the "post_max_size" setting in the php.ini? How big of a file are you trying to upload? Quote Link to comment https://forums.phpfreaks.com/topic/253459-_files-not-working/#findComment-1299243 Share on other sites More sharing options...
SergeiSS Posted December 19, 2011 Share Posted December 19, 2011 scootstah, if he has incorrect settings in php.ini, he would get FILES archive and get error code not equal to 0. I think something is wrong in his form, maybe any quote is missed or anything else. That's why I ask TC - show code of you form. Quote Link to comment https://forums.phpfreaks.com/topic/253459-_files-not-working/#findComment-1299247 Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 scootstah, if he has incorrect settings in php.ini, he would get FILES archive and get error code not equal to 0. I think something is wrong in his form, maybe any quote is missed or anything else. That's why I ask TC - show code of you form. This is true if upload_max_filesize is exceeded, but if post_max_size is exceeded then $_POST and $_FILES will be empty. Quote Link to comment https://forums.phpfreaks.com/topic/253459-_files-not-working/#findComment-1299249 Share on other sites More sharing options...
joequah1 Posted December 19, 2011 Author Share Posted December 19, 2011 Are you exceeding the "post_max_size" setting in the php.ini? How big of a file are you trying to upload? erm is 3kb big? most the image i upload is below 100kb. Quote Link to comment https://forums.phpfreaks.com/topic/253459-_files-not-working/#findComment-1299251 Share on other sites More sharing options...
joequah1 Posted December 19, 2011 Author Share Posted December 19, 2011 scootstah, if he has incorrect settings in php.ini, he would get FILES archive and get error code not equal to 0. I think something is wrong in his form, maybe any quote is missed or anything else. That's why I ask TC - show code of you form. <?php require_once('includes/CssJs.php');?> <form method="post" action="" enctype="multipart/form-data"> <input type="hidden" name="companyID" value="<?php echo $_GET['id']; ?>"/> <?php require_once ('User_ControlPanel_UploadImage.php'); $msg = array(); $fileName = array(); if(!empty($_POST['submitAddGallery'])){ $companyID = $_POST['companyID']; for($int = 1 ;$int<=5;$int++) { if(!empty($_FILES["file_$int"]['name'])) { $name = $_FILES["file_$int"]['name']; $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION)); $temp = str_replace(".$ext", "", $name); $save_as = uniqid("$temp") . '.' . $ext; $fileName[] = $save_as; $msg[] = uploadImage($_FILES["file_$int"],$companyID,$save_as); } } $msg = array_filter($msg); if(!empty($msg)) { echo '<div id="validations-error"><ul>'; foreach ($msg as $value) { echo "<li><div class='close'>$value</div></li>"; } echo '</ul></div>'; } else { foreach($fileName as $value) { $displayOrder = getCount("SELECT * FROM CompanyGallery_TB WHERE CompanyID ='$companyID' ") + 1; $Images = $companyID."/".$value; $sql = "INSERT INTO CompanyGallery_TB (Images,DisplayOrder,Caption,IsCover,IsDisplay,CompanyID) VALUES('$Images','$displayOrder','','No','Yes','$companyID')"; $result = insertSQL(DB_HOST,DB_USER,DB_PASS,DB_NAME,$sql); echo "<script>alert('$result, ok');</script>"; } $today = date("Y-m-d H:i:s"); $sql = "UPDATE Company_TB SET updatedDate = '$today' WHERE CompanyID = '$companyID'"; $result = insertSQL(DB_HOST, DB_USER, DB_PASS, DB_NAME, $sql); echo "<script>alert('Image(s) upload successfull.');</script>"; } } ?> <div id ="user_content" style="min-height: 100px; border:none; width: 300px;"> <table class="list" style="width:365px;"> <tr> <td colspan="3" class="title">Add Gallery</td> </tr> <tr> <td>Images 1</td> <td class="dotted">:</td> <td><input type="file" name="file_1"/></td> </tr> <tr> <td>Images 2</td> <td class="dotted">:</td> <td><input type="file" name="file_2"/></td> </tr> <tr> <td>Images 3</td> <td class="dotted">:</td> <td><input type="file" name="file_3"/></td> </tr> <tr> <td>Images 4</td> <td class="dotted">:</td> <td><input type="file" name="file_4"/></td> </tr> <tr> <td>Images 5</td> <td class="dotted">:</td> <td><input type="file" name="file_5"/></td> </tr> </table> <input type="submit" name="submitAddGallery" value="Submit" id="submitAddGallery"/> </div> </form> <script type="text/javascript"> // $("#submitAddGallery").click( // function () { // parent.$.fn.colorbox.close(); // }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/253459-_files-not-working/#findComment-1299252 Share on other sites More sharing options...
joequah1 Posted December 19, 2011 Author Share Posted December 19, 2011 Could it because of the server settings? Quote Link to comment https://forums.phpfreaks.com/topic/253459-_files-not-working/#findComment-1299255 Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 Could it because of the server settings? Like I said, what is post_max_size set to in the php.ini? And how big are the files you are trying to upload? Quote Link to comment https://forums.phpfreaks.com/topic/253459-_files-not-working/#findComment-1299261 Share on other sites More sharing options...
joequah1 Posted December 19, 2011 Author Share Posted December 19, 2011 Could it because of the server settings? Like I said, what is post_max_size set to in the php.ini? And how big are the files you are trying to upload? i never set the post_max_size and the files im trying to upload is between 3kb to 1mb. i tried to upload with 3kb and it don works. and i tried to add in these ini_set ("file_uploads","On"); ini_set ("upload_max_filesize", "128M"); ini_set("meemory_limit", "96M"); ini_set("post_max_size", "64M"); it still wont work. Quote Link to comment https://forums.phpfreaks.com/topic/253459-_files-not-working/#findComment-1299266 Share on other sites More sharing options...
sw0o0sh Posted December 19, 2011 Share Posted December 19, 2011 Does the uploads directory have the permissions to write files? Quote Link to comment https://forums.phpfreaks.com/topic/253459-_files-not-working/#findComment-1299270 Share on other sites More sharing options...
joequah1 Posted December 19, 2011 Author Share Posted December 19, 2011 Does the uploads directory have the permissions to write files? i got the permission to write files. And i Check the php info in the server php.ini the post_max_size has no value. so does this mean if post_max_size has no value we cant upload files? Quote Link to comment https://forums.phpfreaks.com/topic/253459-_files-not-working/#findComment-1299271 Share on other sites More sharing options...
sw0o0sh Posted December 19, 2011 Share Posted December 19, 2011 post_max_size = 8M that's what mine says, I'm going to say yes and assume you need something there Quote Link to comment https://forums.phpfreaks.com/topic/253459-_files-not-working/#findComment-1299272 Share on other sites More sharing options...
joequah1 Posted December 19, 2011 Author Share Posted December 19, 2011 post_max_size = 8M that's what mine says, I'm going to say yes and assume you need something there im trying to set ini_set("post_max_size","64MB"); still no value. does this mean i need to change from the server? Quote Link to comment https://forums.phpfreaks.com/topic/253459-_files-not-working/#findComment-1299273 Share on other sites More sharing options...
joequah1 Posted December 19, 2011 Author Share Posted December 19, 2011 i changed to 64M now. still not working. so whats the problems now? Quote Link to comment https://forums.phpfreaks.com/topic/253459-_files-not-working/#findComment-1299276 Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 You marked this solved, so does that mean you got it to work? Quote Link to comment https://forums.phpfreaks.com/topic/253459-_files-not-working/#findComment-1299340 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.