top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to Get the Uploaded File Information in the Receiving Script?

+1 vote
350 views
How to Get the Uploaded File Information in the Receiving Script?
posted Jun 13, 2014 by Rahul Mahajan

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

PHP script can get the uploaded file information through the predefined array called $_FILES. Uploaded file information is organized in $_FILES as a two-dimensional array like:
$_FILES[$fieldName]['name'] - The Original file name on the browser system.
$_FILES[$fieldName]['type'] - The file type determined by the browser.
$_FILES[$fieldName]['size'] - The Number of bytes of the file content.
$_FILES[$fieldName]['tmp_name'] - The temporary filename of the file in which the uploaded file was stored on the server.
$_FILES[$fieldName]['error'] - The error code associated with this file upload.

The $fieldName is the name used in the < INPUT TYPE=FILE, NAME=fieldName>.

answer Jun 14, 2014 by Vrije Mani Upadhyay
0 votes

PHP script gets the information of uploaded file using a function $_FILES.
$_FILES[$controlName]['name'] - The Original name of file..
$_FILES[$controlName]['tmp_name'] - The temporary filename of the file in which the uploaded file was stored on the server.
$_FILES[$controlName]['type'] - The type of file uploaded.
$_FILES[$dontrolName]['size'] - The size or memory which that particular file is having.

answer Jun 16, 2014 by Karamjeet Singh
Similar Questions
+1 vote

I'm writing a PHP extension now in c/c++. User uploads a file (could be POST or PUT method, but I can limit it to POST only). I need to capture the file data while being uploaded, without writing it to disk on the server. I need to process the data and (maybe, depending on a situation) send it somewhere else or save it to disk.
Of course I know, that I can process the file after it has been uploaded (saved on disk on the server), but I would like to avoid it. I also need to do something opposite: I need to generate a file "on the fly" and send it
to the user. All metadata of the generated file is known beforehand (e.g. size, name).

I've been searching around for some time now and I could not find anything even close to the solution. Is there any example(s) or existing PHP extension that do(es) something like this (at least something simmilar) ? If you could give me any pointers that would be awesome.

0 votes

I have a requirement, wherein I need to allow vanilla uploads of files to a HTTPD server.

Any client can upload any number of files (one at a time). Also, there is just one directory, where the files get stored "finally" (that is, after being copied from the temporary location, via "move_uploaded_file")

Also, I have been able to get the simple file uploading running via PHP, by picking up one of the numerous "Hello World" examples available :)

Now, I am facing the following use-case ::

1) User 1 starts uploading a large file, say "big_file.avi".

2) Meanwhile, user 2 also starts uploading a (different) file, but with the same name "big_file.avi".

In an ideal scenario, user 2 should be prompted with a message, that a file of the same name is already being uploaded by someone else somewhere. Is there a way to do this?

( Note that, had the user 2 started uploading AFTER user 1 had finished with the upload, we could probably modify the PHP-script at the sever-side, to let user-2 know that a file of the same name already exits. But I am failing to find a solution, when the user 2 starts the upload WHILE the large file of user 1 is in the process of completing uploading).

Any way the issue may be solved?

...