LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-11-2003, 06:15 PM   #1
rvn
LQ Newbie
 
Registered: Oct 2003
Posts: 21

Rep: Reputation: 15
php header redirect problem after upload


I am having the strangest problem.
I have a php page that I am using to accept file upload.

the script to do this is on a page called upload.php

for some reason if i upload the files, everything will work fine
except the header("location:$url"); at the end.
or it seemingly not works... i mean by this that i get a "This page cannot be displayed error" but if i hit F5 for refresh it will take me to the next page.

i tried debugging the old fashioned way, stripping away everything
until i came down to this...

for my upload form.
<form enctype="multipart/form-data" action="upload.php" method=post>
<input type="hidden" name="action" value="addfile">
<input type="file" name="uf[]"><br>
<input type="file" name="uf[]"><br>
<input type="submit" class="submit" value="upload file(s)"><br>
</form>


here is the only code i have on upload.php
<?php
header("location:http://www.yahoo.com");
?>


If i remove the input type="file" from the form... the redirect works fine, like this:
<form enctype="multipart/form-data" action="upload.php" method=post>
<input type="hidden" name="action" value="addfile">
<input type="submit" class="submit" value="upload file(s)"><br>
</form>

obviously this is useless.

for some reason the act of passing the input "type=file" into the upload page makes the header function act retarded.

Whats worse is, i have a similar function , working elsewhere on the same server!!
but ive stripped this code down to so little... and it still doesnt work...

anyone know a sure fire way to make the header work everytime?
 
Old 02-08-2004, 07:20 AM   #2
marghorp
Senior Member
 
Registered: Jan 2004
Location: Slovenia
Distribution: Slackware 10.1, SLAX to the MAX :)
Posts: 1,040

Rep: Reputation: 45
Re: php header redirect problem after upload

Hi!

The problem you are experiencing is because headers can only be sent before any output has been made to the browser. Which means if you send any HTML to the browser, the redirect will not work. Headers must be sent before any output to work correct and they do in that case. As you have tried it yourself and said

"If i remove the input type="file" from the form... the redirect works fine"

but if you output HTML, they do not work anymore.

You have two options. Send headers at the start of the file. I think the file will be executed anyway (the rest of the PHP, but not too sure about that). The other option is to do somekind of different redirect (javascript or some other script, which can redirect in between the HTML).

Hope this helps
 
Old 02-08-2004, 08:19 AM   #3
marghorp
Senior Member
 
Registered: Jan 2004
Location: Slovenia
Distribution: Slackware 10.1, SLAX to the MAX :)
Posts: 1,040

Rep: Reputation: 45
A little more help

There is one more thing you could do. That is in php.ini, probably located in /etc directory.

In that file you can configure options for PHP. One of those options in buffer_output or buffer_input. It says in that file, that turning this on, you can send headers even if you have sent any HTML before. But it is a little performance slow downer.

Marghorp
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Php redirect script newuser455 Programming 2 08-03-2005 08:23 PM
Coding a redirect function in php mrobertson Programming 2 06-22-2005 09:40 AM
how to redirect PHP code to another page bahadur Programming 3 03-21-2005 06:59 AM
PHP Redirect Elijah Programming 2 09-09-2004 10:56 PM
File upload via PHP!!! saravanan1979 Programming 0 02-14-2002 02:55 AM


All times are GMT -5. The time now is 09:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration