• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 491
  • Last Modified:

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
0
nalla_bts
Asked:
nalla_bts
1 Solution
 
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now