File upload causing Page Cannot be displayed using php mysql

Hello,

I am implemeting file upload to mysql as blob using php. When I select a file to upload and click submit (I am posting the form to SELF), IE shows "Page cannot be displayed" error message. When I refresh the page, the form works as expected and the file upload is successful.

I checked couple of forums and it indicated that the error might be related to configuration settings on apache. I tried those changes but not luck yet.

Here are those links:

http://www.vbulletin.com/forum/showthread.php?126376-Page-cannot-be-displayed-on-Upload

http://www.infoqu.com/dev/php-development/file-uploads-causing-quotthe-page-cannot-be-displayedquot-98235-1/

There were few instances where the file upload worked fine but, now it keeps throwing error message.

Any directions in resolving this issue is highly appreciated.

Thanks
LVL 1
nalla_btsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gmckeown99Commented:
Check the php.ini settings first:

upload_max_filesize
post_max_size

If you have a slow upload speed (as many DSL and cable connections have), you could be timing out.

It is important to use the enctype="multipart/form-data" so that the browser uploads the binary data correctly.

<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            <input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
            <input name="userfile[]" type="file" />
            <input type="submit" value="Submit" />
        </form>

Is this on IE or Firefox, or both. IE is the best browser, never crashes of anything. ; )

0
subscriptCommented:
Any process that involves extended data transfer over the web can get hung up, in my experience.

I would try submitting the form to a separate upload/processing page.
This page would (after upload event is finished) trigger a redirect that sends the user to either a results page or the original form page... along with feedback that file was successfully uploaded.

Sometimes breaking up the process over a couple different pages (http requests) can help the application/browser digest the process/rendering more easily.

Might be worth a try.
Let me know if that does/doesn't help.
0
Ludwig DiehlSystems ArchitectCommented:
try this. It works on IE and FF and sure it will work on almost any browser
<?php 
$uploadedFile=null;
if(is_uploaded_file($_FILES['file_upload']['tmp_name']))
    if(move_uploaded_file($_FILES['file_upload']['tmp_name'],dirname(__FILE__).'/'.$_FILES['file_upload']['name']))
    {
        $uploadedFile  = $_FILES['file_upload']['name'];
    }
?>
<html>
    <head>
    </head>
    <body>
        <form action="" enctype="multipart/form-data" method="POST">        
            <input type="hidden" name="MAX_FILE_SIZE" value="10000000000000000" />
            <input type="file" name="file_upload" />        
            <input type="submit" name="submit" value="Upload" />
            <br />
            <?php
                if($uploadedFile)                
                    echo "Uploaded File: <span style=\"font-weight: bold;color: green;\">$uploadedFile</span>";
                else
                    echo "<span style=\"color: red;font-weight:bold\">No File uploaded!</span>";
            ?>
        </form>
    </body>
</html>

Open in new window

0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

nalla_btsAuthor Commented:
@subscript - I included the upload script in another page (upload.php) and on form submit, I am posting it to upload.php.

At the end of file, I used header("Location: url ") but, no luck. If I refresh the page, it takes me to the html page and also the file upload is successful.

If I remove the header("Location: url), and use echo to display a message, it works and shows the message. Is this error because of header("Location: ") ?

0
nalla_btsAuthor Commented:
@gmckeown99 - I checked the values of upload_max_filesize and post_max_size. I set pretty high values to these config values and made sure than post_max_size > upload_max_size.

My form also has enctype="multipart/form-data". Just a reminder that file is uploaded successfully to the DB, but shows connection time out exception.

Fire Fox shows:

The connection was reset
The connection to the server was reset while the page was loading.
0
subscriptCommented:
On the separate upload.php page...

Are you testing that the upload process is completed before attempting redirect?
ie. something like:

if ($file_is_uploaded) {
   /* redirect now */
}

If the header() redirect isn't working for some reason but echo is... you could consider using a Javascript redirect instead, such as:

if ($result) {
echo '
<SCRIPT language="JavaScript">
<!--
window.location="http://someplace.com";
//-->
</SCRIPT>
';
}

Thoughts?
0
nalla_btsAuthor Commented:
I included the javascript redirection code but, no luck. But, when I give the redirect url as google.com, it works.

The page which I am redirecting to is a WordPress page? Does it have anything to do with WordPress?
0
nalla_btsAuthor Commented:
The issue is resolved:

I had mysql_close(); after I ran the sql query to insert the record into the DB. I am really unsure how closing the sql connection was causing the http connection to close.

It works on my local machine with mysql_close().

Strange?
0
subscriptCommented:
Huh. Well, without knowing all the details -- hard to say.

Happy you got it resolved anyway. Good luck to you!


0
ee_autoCommented:
Question PAQ'd, 500 points refunded, and stored in the solution database.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.