Jump to content

file uploads


kaliok

Recommended Posts

Could I get an opinion on the following code, I believe it is fine, but sometimes when trying to upload a file it will just hang, without going to an error or timing out. The problem seems to be intermittent and seems to be more prone to not working with larger files, which leads me to believe that the problem is with the shared host I am using. Is this a correct assumption? If there is a problem with the script could someone suggest a better solution. Thanks in advance.

 

//--------------------------------------------------------------------------

// try to upload the pdf (if the file name has not already been used)

  if (strlen($check_pdf_check)!=0) 
  {
       if ($pdfOK==1) //variable set beforehand if the file name is not already in use
      {
            $target = "../pdfs/";
            $check_pdf = $_FILES['pdf']['name'];
            $check_pdf = str_replace(" ","", $check_pdf);
            $check_pdf=strtolower($check_pdf);

            $target = $target.$check_pdf;
            $uploaded_size = $_FILES['pdf']['size'];
            $uploaded_type = $_FILES['pdf']['type'];
            
            if ($uploaded_size > 2000000) 
            { 
        echo "Your pdf is too large!<br>"; 
                $pdfOK=0; 
             }

     if ($uploaded_type !="application/pdf") 
     { 
        echo "The file you selected as pdf document does not appear to be a pdf document!<br>"; 
                $pdfOK=0; 
              }

            if ($pdfOK==0) 
            { 
                echo "Sorry the upload was not successful.<br>"; 
            } 
            else 
    { 
                $userfile_tmp_csapdf = $_FILES['pdf']['tmp_name'];
                $userfile_tmp_csapdf = str_replace(" ","", $userfile_tmp_pdf);
                if(move_uploaded_file($userfile_tmp_pdf, $target)) 
                { 
	   echo "The pdf file ".basename($check_pdf). " has been uploaded.<br>"; 
         } 
                 else 
                 { 
                   echo "Sorry, there was a problem uploading your pdf.";
                   $pdfOK=0; 
	 } 
     } 
       }
  }	

//------------------------------------------------------------------

 

Link to comment
Share on other sites

The script seems fine to me, with the error handling and stuff. Ive had this same problem, with uploading files with big size the script hanged and did not show any custom or core errors. Normaly it should show up the custom error or at least bring an error because the filesize exceeds 'upload_max_filesize'. Maybe it has to do with php hanging while computing filesize or attemping to upload to temp. Id be glad to hear some explenations.

Link to comment
Share on other sites

I have checked several forums, books and tutorials and all of them seem to give a similar procedure for uploading files, I did speak to the host, who ran their own tests and came back with the following explanation, I haven't called them back yet, because I want to be absolutely sure I am not in the wrong.

 

We've checked your domain with a test suite, and we believe that PHP on this

server is operating correctly. You may need to contact the company who

created the PHP upload script you're using for further support using their

software.

 

I am assuming that if a script works some of the time, then the script works, and the reason it doesn't work is not a problem with the script, would people agree that this is a fair assumption?

Link to comment
Share on other sites

I did some research and found some information which may be the case:

 

- max_file_size cant be different then upload_max_filesize

- memory_limit must be set high enough to handle big filesizes

- max_execution_time must be high enough for the script to keep running while uploading

- post_max_size must be high enough to support big filesizes in post data

 

The hosting company guy may be right, as he cant do much about your own php configuration. Usually hosting companies let u create a custom php.ini but im not sure u can change everything in it. Maybe u can contact them and ask about the real issue and if u can modify those values in php.ini. By the way, your script has nothing to do with it.

Link to comment
Share on other sites

I don't think the hosting company allows me to modify the php.ini file, but I just wanted to make sure that my script was written correctly. I also found similar information. Thanks for your help. I will endeavour to see if I can get them to look at their limits or better yet let me have a look at them. Confusing though, they are a big company and one would have thought I am not the only customer having problems with uploading files. They are not even that large files, 900k or so! Thats why I want to be sure its not my script. Thanks again.

Link to comment
Share on other sites

Could someone confirm the following for me please:

 

I have continued to to investigate the problem I am having. To test whether it is my code, I completely took out the script that checks the pdf file and uploads it. I left the front end form that has the browse button on it intact. After selecting a file to upload the user hits submit and the front end form page goes through to the next page where I have the script that I commented out. However I am still having problems getting to that page to load if a file is selected for upload in the form (the page is still hanging).

 

I know this may sound obvious, but would I therefore be correct in assuming that although I have removed my script being used to calculate or obtain the file size or place the file into a temp directory, the server that it would be running on is regardless performing that task, and that therefore the problem is related to the hosting company?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
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.