# Question on file upload

- Thread: https://externals.io/message/44127
- Original archive: https://news-web.php.net/php.internals/44127
- Started by Bharat Nagwani on 2009-06-02T20:55:06+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #44127 — Bharat Nagwani — 2009-06-02T20:55:06+00:00

URL: https://externals.io/message/44127#44127

Hello,

I want to change the way file upload processing is done in php. We have a http server (appweb)
that puts the uploaded file to a temp directory. This file has headers at the beginning and end.

I am looking at code rfc1867.c. This code takes the temp file and seems to extract the real file.
I want to change it so instead of entire file, I can run a system awk command to trim the
header lines to get the actual file.

Has anyone done something similar? I cant find the place where the actual file is being read?
Can someone please point to that.

This is php 5.2 on bsd.

Thanks

---

## #44128 — Matt Wilson — 2009-06-02T23:21:45+00:00

URL: https://externals.io/message/44127#44128 · In reply to: #44127

I'm not sure if you're looking to change the C implementation or not,  
but you could always bypass the internal processing of the file. Set  
post_max_size to 0 and parse the HTTP_RAW_POST_DATA manually.




> Hello,
>
> I want to change the way file upload processing is done in php. We  
> have a http server (appweb)
> that puts the uploaded file to a temp directory. This file has  
> headers at the beginning and end.
>
> I am looking at code rfc1867.c. This code takes the temp file and  
> seems to extract the real file.
> I want to change it so instead of entire file, I can run a system  
> awk command to trim the
> header lines to get the actual file.
>
> Has anyone done something similar? I cant find the place where the  
> actual file is being read?
> Can someone please point to that.
>
> This is php 5.2 on bsd.
>
> Thanks

---

## #44129 — Bharat Nagwani — 2009-06-02T23:30:24+00:00

URL: https://externals.io/message/44127#44129 · In reply to: #44128

Yes I am looking to change the C implementation.

The problem is - the uploaded temp file is already created by httpd server even before it gets to php.

In php I just need to find this temp file, trim the headers and avoid
file copy by php being done by following code in rfc1867.c

while (!cancel_upload && (blen = multipart_buffer_read(mbuff, buff, sizeof(buff), &end TSRMLS_CC)))
     {
      if (php_rfc1867_callback != NULL) {
         multipart_event_file_data event_file_data;
         event_file_data.post_bytes_processed = SG(read_post_bytes);
         event_file_data.offset = offset;
         event_file_data.data = buff;
         event_file_data.length = blen;
         event_file_data.newlength = &blen;
         if (php_rfc1867_callback(MULTIPART_EVENT_FILE_DATA,  
                &event_file_data, &event_extra_data TSRMLS_CC) == FAILURE) {
                
...

While following multipart_buffer_read I cannot find the place where it is reading the temp file to fill this buffer.

Thanks

-----Original Message-----
From: Matt Wilson [mailto:shadda@gmail.com] 
Sent: Tuesday, June 02, 2009 4:22 PM
To: Bharat Nagwani
Cc: internals@lists.php.net
Subject: Re: [PHP-DEV] Question on file upload

I'm not sure if you're looking to change the C implementation or not,  
but you could always bypass the internal processing of the file. Set  
post_max_size to 0 and parse the HTTP_RAW_POST_DATA manually.




> Hello,
>
> I want to change the way file upload processing is done in php. We  
> have a http server (appweb)
> that puts the uploaded file to a temp directory. This file has  
> headers at the beginning and end.
>
> I am looking at code rfc1867.c. This code takes the temp file and  
> seems to extract the real file.
> I want to change it so instead of entire file, I can run a system  
> awk command to trim the
> header lines to get the actual file.
>
> Has anyone done something similar? I cant find the place where the  
> actual file is being read?
> Can someone please point to that.
>
> This is php 5.2 on bsd.
>
> Thanks
