homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Rewrite & File Upload
Can't get file uploads working with mod rewrite

 9:27 pm on Sep 25, 2007 (gmt 0)

I am using htaccess to make it possible for dynamic user pages such as www.site.com/username. Everything goes through index.php and I capture the variables accordingly. Everything works. Forms work all but file uploads. I can't get it to even post. However when i check to see if the submit button is submitted, it will work. All my code worked fine before I did the rewrite to go live and now I'll have to do another 4 months of coding to get it working right. Any help would be much appreciated. I will even pay someone to help me get this straightened out.



 11:14 pm on Sep 25, 2007 (gmt 0)

It might be helpful to post the rewrite code that you used. In particular, if the syntax is not absolutely correct and you get an unintended external redirect instead of an internal rewrite, you may run smack into a problem cited in the HTTP/1.1 specification:
If the 302 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued.

In other words, 302 redirects are not usually allowed for POSTs.



 5:56 am on Sep 26, 2007 (gmt 0)

Thank you for the reply Jim. Here is what I have in the htaccess file:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Then, index.php contains the following:

$path = explode('/', $_GET['q']);
$var = $path[0];


 1:43 pm on Sep 26, 2007 (gmt 0)

Well, GET and POST are two entirely different HTTP methods, and your script supports GET, but does not appear to support POST. (To be clear, GET is used by a client to provide data to a script by attaching a query-string to a URL, while POST is used by the client to send the data in the HTTP message-body itself -- In simple terms, the client POSTs (sends) a "page" of data to the server.)

So how does your script support POST? Do you have a different "upload" script, or does the current script handle POSTs as well?

mod_rewrite can use a RewriteCond to test the HTTP method and rewrite to different scripts based on the HTTP method used by the client, if that might help you.



 2:43 pm on Sep 26, 2007 (gmt 0)

Thanks again Jim, I really appreciate your time. Inside index.php I have the following:

$path = explode('/', $_GET['q']);
$var = $path[0];

if($var == "testing"){
echo ("yes");

<form action="/testing/" method="post" enctype="multipart/form-data" name="form">
<input type="file" name="upload" id="upload">
<input name="submit" type="submit" value="submit">


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved