0

In PHP I have the following code that gets a file submitted through CGI:

move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)

The file is being sent as

Content-Disposition: form-data; name="userfile"; filename="filename"
Content-Type: application/octet-stream

The file being upload is of type PNG.

How do I access the data that $_FILES is getting through perl?

I can use CGI.pm with

$query->upload("filename");

But how do I get the data that is in the "Content-Disposition" part of the header?

1 Answer 1

2

To quote the doc:

When a file is uploaded the browser usually sends along some information along with it in the format of headers. The information usually includes the MIME content type. Future browsers may send other information as well (such as modification date and size). To retrieve this information, call uploadInfo(). It returns a reference to a hash containing all the document headers.

   $filename = param('uploaded_file');
   $type = uploadInfo($filename)->{'Content-Type'};
   unless ($type eq 'text/html') {
      die "HTML FILES ONLY!";
   }

Though the param() ought to return the filename too (also usable as a filehandle, but that's deprecated and upload() should be used for that instead).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.