Jump to content

return blank page if not all file upload


Recommended Posts

hi , i have an error in my php . It will display successful only if all file being upload , if there have one file not upload . it go to blankpage not tell any error or success.I have file that being upload to different path folder


 $fileName14 = basename($_FILES["penaja"]["name"]);
        $targetFilePath14=$targetDir14. $fileName14;
        $fileType14 = pathinfo($targetFilePath14,PATHINFO_EXTENSION);
        $allowTypes14=  array('pdf','PDF','docx','DOCX');
         $targetDir15 ="folder/pda-semakan/kesihatan/";
        $fileName15 = basename($_FILES["umpapkp"]["name"]);
        $targetFilePath15=$targetDir15. $fileName15;
        $fileType15 = pathinfo($targetFilePath15,PATHINFO_EXTENSION);
        $allowTypes15=  array('pdf','PDF','docx','DOCX');

         $targetDir16 ="folder/pda-semakan/jhepa/";
        $fileName16 = basename($_FILES["umpajhepa"]["name"]);
        $targetFilePath16=$targetDir16. $fileName16;
        $fileType16 = pathinfo($targetFilePath16,PATHINFO_EXTENSION);
        $allowTypes16=  array('pdf','PDF','docx','DOCX');

        if(in_array($fileTypeg, $allowTypesg)){
       if(in_array($fileType, $allowTypes)){
         if(in_array($fileType1, $allowTypes1)){
           if(in_array($fileType2, $allowTypes2)){
             if(in_array($fileType3, $allowTypes3)){
              if(in_array($fileType4, $allowTypes4)){
                if(in_array($fileType5, $allowTypes5)){
                 if(in_array($fileType6, $allowTypes6)){
                        if(in_array($fileType7, $allowTypes7)){

            // Upload file to server
                if(move_uploaded_file($_FILES["gambar"]["tmp_name"], $targetFilePathg)){
                if(move_uploaded_file($_FILES["surat"]["tmp_name"], $targetFilePath)){
                      if(move_uploaded_file($_FILES["ic"]["tmp_name"], $targetFilePath1)){
                         if(move_uploaded_file($_FILES["sijilkelahiran"]["tmp_name"], $targetFilePath2)){ if(move_uploaded_file($_FILES["sijilspm"]["tmp_name"], $targetFilePath3)){
                         if(move_uploaded_file($_FILES["sijilberhenti"]["tmp_name"], $targetFilePath4)){  
                          if(move_uploaded_file($_FILES["sijilmatrik"]["tmp_name"], $targetFilePath5)){   
                           if(move_uploaded_file($_FILES["sejulai"]["tmp_name"], $targetFilePath6)){
                                   if(move_uploaded_file($_FILES["bmjulai"]["tmp_name"], $targetFilePath7)){                       


Link to comment
Share on other sites

after you use an array name for the form field, so that you can have a set of fields, or one field with the multiple attribute, without typing out a series of name-numbered field names, be advised that using a html form submission to upload multiple files will try to send all the data in one http request. this will easily cause the size of the request to exceed the post_max_size setting on the web server, which will cause the upload to fail and give empty $_POST and $_FILES arrays. even if uploading a single file, you can easily exceed the post_max_size setting.

to handle this possibility, your form processing code must first detect if a post method form was submitted, then detect if the $_FILES array is empty or not before trying to reference any of the $_FILES data. there are other things that can cause the $_FILES array to be empty, such as uploads not being enabled or bad markup in the form. however, once you have successfully uploaded any file with your code, the total size of the form data will the reason for an empty $_FILES array. your code must detect this condition and setup a message for the user telling them that the total size of the submitted data was too large and could not be processed. once you have determined that there is data in the $_FILES array, you must test the ['error'] element for each file and only use the uploaded file information if there is no upload error. for the upload errors that the user has control over, you must setup a unique and helpful error message telling them exactly what they did wrong and how to correct it. for the upload errors the user has no control over, you would setup a general failure message for the user and log all the actual information about the error so that you know it is occurring and then can find and fix what's causing it on the server.

to address uploading multiple files, you would need to use ajax to upload the files one at a time. there are existing scripts you can find on the web showing how to do this.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.