473,396 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

[FAQ] File uploading

Q: How should I handle file upload?
A: File uploading requires HTML form of content type
"multipart/form-data". The file content has to be POSTed/submitted via
the form and once the file is uploaded, it will be available at the
"upload_tmp_dir" (usually /tmp) directory. Then you may move that file
to another directory using move_uploaded_file(); file name will be
available in the superglobal $_FILES['userfile']['tmp_name'].

Refer:
http://www.php.net/features.file-upload
http://www.faqs.org/rfcs/rfc1867.html

Q: How to upload a huge file to the server?
A: Uploading depends on various factors:
1. Browser timeout/capacity/configuration
2. Available space and memory at the server
3. PHP's setting to handle uploads and POST data

In most of the cases, you could be able to adjust only the (3)

Refer:
http://www.php.net/ini.core#ini.sect.file-uploads
Q: How to implement progress/status bar for file uploading?
A: This is impossible in PHP as it doesn't populate HTTP_RAW_POST_DATA
natively. Anyway, there are few hacks available:
1. Patching PHP <http://pdoru.from.ro/upload-progress-meter/>
2. Using Perl <http://www.raditha.com/php/progress.php>
3. Finding the size of "upload_tmp_dir" directory at some interval,
originally suggested by Reader Ron in
<news:42**************************@posting.google. com>
Caveats:
There is no speculation that patching solution will be implemented
natively in PHP.
(3) seems to be the only pure PHP hack; however it won't work when
multiple files are been uploaded at the same time.

Jul 17 '05 #1
9 2352
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in message
news:11********************@o13g2000cwo.googlegrou ps.com...
Q: How to implement progress/status bar for file uploading?
A: This is impossible in PHP as it doesn't populate HTTP_RAW_POST_DATA
natively. Anyway, there are few hacks available:
1. Patching PHP <http://pdoru.from.ro/upload-progress-meter/>
2. Using Perl <http://www.raditha.com/php/progress.php>
3. Finding the size of "upload_tmp_dir" directory at some interval,
originally suggested by Reader Ron in
<news:42**************************@posting.google. com>


I wouldn't say it's impossible in PHP. It's possible to use PHP CLI to
implement same technique used as the Perl script. It would actually be
fairly easy:

1. Set up PHP CLI as CGI
2. In the upload script, open php://stdin
3. Get the size of the request from the HTTP header
4. Save the body of the request to a temp file somewhere, saving the
progress info in a file
5. Open a socket connection to localhost and send the saved request body to
a regular server script (that is, handled by mod_php)

This setup is nice since the end point of the operation is back at the PHP
application, so it can be implemented fairly painlessly.
Jul 17 '05 #2
Chung Leong wrote:
Q: How to implement progress/status bar for file uploading?
A: This is impossible in PHP as it doesn't populate HTTP_RAW_POST_DATA natively. Anyway, there are few hacks available:
1. Patching PHP <http://pdoru.from.ro/upload-progress-meter/>
2. Using Perl <http://www.raditha.com/php/progress.php>
3. Finding the size of "upload_tmp_dir" directory at some interval, originally suggested by Reader Ron in
<news:42**************************@posting.google. com>
I wouldn't say it's impossible in PHP. It's possible to use PHP CLI

to implement same technique used as the Perl script. It would actually be fairly easy:

1. Set up PHP CLI as CGI
2. In the upload script, open php://stdin

<snip>

Sounds convincing. I don't have time to test and see. Also, the
links I've looked at say that we cannot read the post data (even via
php://stdin (?)) when the form data encoding is "multipart/form-data".
If you have time, you may release this plug in your webpage so that we
may easily link to that.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #3
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Sounds convincing. I don't have time to test and see. Also, the
links I've looked at say that we cannot read the post data (even via
php://stdin (?)) when the form data encoding is "multipart/form-data".
If you have time, you may release this plug in your webpage so that we
may easily link to that.


The CLI version of PHP doesn't process the request, that's why we use that
instead of the PHP CGI.

I just got the script working. Unfortunately, I couldn't get it to work on
my ISP account. Apache is set up to use suExec so the CGI script can't write
to session files created by the main application. In order to use this
technique you need to have full control over the server. For one thing, CLI
might not be present. For another, you have to use conditional logging.
Otherwise repeated requests to stats page (every second) will very quickly
jam up your access log.

If anyone is interested I can post the code.
Jul 17 '05 #4
Chung Leong wrote:
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in message news:11**********************@o13g2000cwo.googlegr oups.com... <snip> If anyone is interested I can post the code.


Yes, me. Would be better if you could document and release the plug
in your webpage also (apart from posting here), so that we may easily
link to that from c.l.php faq.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #5
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Chung Leong wrote:
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in

message
news:11**********************@o13g2000cwo.googlegr oups.com...

<snip>
If anyone is interested I can post the code.


Yes, me. Would be better if you could document and release the plug
in your webpage also (apart from posting here), so that we may easily
link to that from c.l.php faq.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/


Okay, I just got it to work at my ISP account. Turns out having the CGI PHP
access the same session files as mod_php was a bad idea. Occasionally a
session would get corrupted for some reason.

Here's a little demo:
http://www.conradish.net/bobo/upload.php

I will have to spend some time writing up some instructions and explanation
on how it works.
Jul 17 '05 #6
Chung Leong wrote:
<snip>
Here's a little demo:
http://www.conradish.net/bobo/upload.php

I will have to spend some time writing up some instructions and explanation on how it works.


Kudos! looks like a cool hack. Once you document it, we may amend
the FAQ entry.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #7
hello
i see the your class
how i can read and recive your class php for uploading file
good bye

Jul 17 '05 #8
How can I set up PHP CLI as CGI?
Do I have to change Apaache's httpd.conf?
The she-bang only works under *nix, can it work on a windows machine?
http://eye.cc -php- web design
Jul 24 '05 #9
joppeaarts wrote:
How can I set up PHP CLI as CGI?
Do I have to change Apaache's httpd.conf?
The she-bang only works under *nix, can it work on a windows machine?
http://eye.cc -php- web design


The PHP CLI works without the intervention of Apache; therefore, you cannot
set it up as CGI, nor can you modify its behaviour by editing the http.conf
file. The she-bang line is ignored under Windows, unless using CygWin
(http://www.cygwin.com/).
JW

Jul 24 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jonathan | last post by:
Hi everyone, I have a problem with the file uploading in Asp.Net and I have read a lot on forums on this but never found an answer. Here is the problem: I know Asp.Net maximum Length for...
4
by: Kenneth Keeley | last post by:
Hi, I have a page that uploads files to my server and I wish to display a "Please wait while uploading" page to the user while the file is uploading. I have been able to redirect the user once the...
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
3
by: Mike Kelly | last post by:
Hi. I've built a page using standard ASP.NET 2.0 features and when I upload a large file (>20MB) to our intranet server, I get a paltry 100KB/s on our 100Mb/s LAN. Simply copying the file, I get...
89
by: Randy Webb | last post by:
There is an updated version of the FAQ at: <URL: http://jibbering.com/faq/newfaq/> The changes/modifications to date are: 2.3 Corrected "span" to "spam". 2.3 Updated with a note about not...
17
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I get the value of a form control? -----------------------------------------------------------------------...
1
by: King | last post by:
Hello, I would like to check to see if the file that I am uploading to my server is of type CSV. I am currently doing that with the following snippet: HttpPostedFile file =...
3
ganesanji
by: ganesanji | last post by:
hi all, I have written a php coding for uploading a file to a specific folder or location in server which is a Linux server. I think the coding for file uploaing is correct. But it does not...
4
rahulephp
by: rahulephp | last post by:
i think i am missing something in the below script: It shows error an do not upload files to destination: Let me know how to solve this: <?php if (isset($_POST)) { $uploadArray=...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.