How do PHP and Apache handle uploaded files? - php

I am working on some PHP upload code.
When I call the copy function it will start a thread in incremental mod. I want to read the full details of the upload functionality for apache and PHP. In fact, I want implementation details for this functionality, namely:
How a file is copied in temp folder
How it is copied to the proper destination
What happens when server is busy and client is sending fix size of chunks
I am trying to upload file from my Android application. I am using this code for uploading. But my most of the files header are changed. Most of my uploaded files' sizes increase. Why its happen? In fact I want to investigate it. My client is Android application and server is apache 2.0 with php 5.
Thanks in advance.

CodeCaster allready gave part of the answer...
Just a really big tip here, php.net has a huge database with ALL of the functions and great examples that goes with them.
This is the main page about handling file uploads (just a table of contents) http://nl3.php.net/manual/en/features.file-upload.php
Here is pretty much everything you need to know:
http://nl3.php.net/manual/en/features.file-upload.post-method.php
W3Schools also has a tutorial on this.
http://w3schools.com/php/php_file_upload.asp

Related

Quick deploy standalone PHP script to accept uploaded files?

I need to accept a large number of images from a 3rd party, and I already have an apache server up and running. As the 3rd party is not tech-savvy, I would like to give them a simple web form to upload files.
They don't need to be able to access the files they've uploaded, although I suppose it would be nice for them to verify what they've already sent, especially being that there is a large number of files.
There is also no requirement to be able to upload all files at once, and I think I can talk them through packaging the files into a 4-5 zip files, so single upload would be acceptable.
If I need to write a PHP script myself then so be it, but I was wondering if such a standalone script already exists in the wild, nice and polished etc :)
Thanks!
Nice ajax file manager:
http://www.ajaxplorer.info/wordpress/demo/
Others:
http://devsnippets.com/article/7-free-powerful-file-managers.html

upload large files 100MB+ progress

I am having a lot of trouble handling large file uploading on the client side. I am looking for a way to show the progress of an upload while that person uploads. Then when it is finished, I need to have the file handled by a php script.
I am currently using http://code.google.com/p/swfupload/ SWFUPLOAD, but it is giving me trouble. It works 100% of the time for small files that are 5MB and so on, but for larger files that are over 100MB I am getting weird behavior. For example, when finished, the upload script does not receive some of the posted variables sometimes and so on. It seems to be breaking for reasons I cannot diagnose and I am quite frankly completely sick of it. (PS all my php settings are fine).
I am just looking for a simple solution for upload progress that does not have too many bells and whistles. I just want the ability to upload large files 100MB-500MB and then have the form posted to an upload script without the client side solution hanging or causing problems.
Has anyone worked on a project that required uploading large files and displaying progress? If so, what was your solution?
Did it involve flash?
Does anyone have any recommendations or a reliable solution?
Thanks in advance.
PHP have a restriction for upload files, you can modify this argument in PHP.ini, but if you can't have access to PHP.ini (some webhosting don't give access to PHP.ini) you can try upload file via FTP.
Can try with this (is in spanish) or with another good.

PHP file upload - Track bytes uploaded with AJAX

I'm trying to figure out if there's a way to get the progress of a file upload with PHP and/or Kohana. My script can upload images, videos, zip, exe, whatever I want really. However the larger the file the longer the user has to wait without any indication.
I was hoping to use some AJAX here to initialise the upload and then report back the progress.
Is this possible with PHP... and can anyone give me an indication of where to start looking.
there is a file upload progress extension for php, see http://www.ultramegatech.com/blog/2010/10/create-an-upload-progress-bar-with-php-and-jquery/ for how to use it.
I like to use a server module to do this sort of thing, mainly because it makes my life as a web developer easier if all I need to do is grab upload statistics from a URL. Nothing has to be changed in your website.
For Nginx there is the Upload Progress module and it should work on all recent releases. You can find code examples on the Nginx Wiki: http://wiki.nginx.org/HttpUploadProgressModule
For Apache there is the Upload Progress too. I haven't used it myself, but it seems fairly straight forward.
If you don't have access to the server configuration, then you might want to fall back onto a pure flash / javascript solution. For this I had good luck with Uploadify in the past, but it requires a bit more work as you now have to upload files in a separate request. Someone should be able to suggest a good HTML5 upload progress plugin too.
you could do this also with apache and APC example

php upload_max_filesize problem

am working on a website and i have a big problem when i tried to upload files, i increase upload_max_filesize and post_max_size and the code still understand only as a max. 10M. for any different folder php accepts 100M. but inside the site folder ( which am working inside) it doesn't understand it. i check for local php.ini or .htaccess.
note: am running a linux server.
For uploading bigger files I would suggest a dedicated uploader plug-in.
Like a SWF of Java. For these reasons:
Security - you can easily encode the sent data (encoding ByteArray in AS3.0 is very easy, can be even tokenized so it is hard to intercept the stream)
Reliability - with simple HTTP requests it is hard to actually monitor the upload progress, so the user might choose to close the uploaded (because he thinks it got stuck)
User friendly - again, progress bar
Not limited by server - if you accept it directly with PHP custom code, you won't need any configuring for annoying things like max file size on upload.
On server-side you will need either a Socket listener, or an HTTP tunnel if unavailable.
You can use JumpLoader, which is a Java applet, and it is able to split large files into partitions, and upload them one by one. Then a PHP script rebuilds the original file from the uploaded partitions on the server.
Plupload can split large files into smaller chunks. See the documentation.
Do you run Apache with mod_security? Then check if the LimitRequestBody is in affect.
Here is a good tutorial about Settings for uploading files with PHP.
Thanks guys,
I found the problem. i don't know why is the file is not visible for me /public_html/site/.htaccess
i tried to overwrite it, and it's seems to be working.
Thanks a lot for efforts.

Using uploaded file without saving to server disk

I have created a PHP script to upload a file, unfortunately I don't have permission to save files on the disk. I have to upload an excel file (using phpexcel), then I have to read all the rows in the file and save to disk, Is there any way for me to process this file without saving to disk, I tried to read $_FILES['file1']['tmp_name'] but it doesn't work.
could u please suggest a method to process this file
Thank you for the consideration
By "save to disk" you mean to send it back to the user for him to download it?
Usually, you shall have write access to (at least) the PHP temporary directory. Have you tried whether the form and script work in a local environment? Maybe there is something elso wrong with the upload?!
Finally: Why so you not have the persmission to save files? Are you allowed to create a subdirectory below you PHP file (via FTP) and give that one full permissions?
I tried to read $_FILES['file1']['tmp_name']
most probably you have just encountered an error.
that happens to beginner programmers very often
you have to repair that error instead of looking for odd workarounds.
Start from checking $_FILES['file1']['error']
what does
var_dump($_FILES['file1']['error']);
say?
Instead of sending your files with a form (multidata over HTTP POST), you can send your files with a little bit of Javascript with the HTTP PUT method to your server.
This scenario is described in the official documentation of PHP -> PUT method support.
Due some restrictions described in the documentation you have to do some workarounds to be able to work it properly.
You can read the direct input stream from your Webserver. The data will be piped from your Webserver to your PHP programm and will be only saved in memory.
To do a PUT Ajax call with jQuery was answered here. You can use a jQuery upload plugin like Uploadify.

Categories