PHP: passing a file to a user defined function
I have a PHP page (registration.php) from where I would submit a file to another form (preocess.php). So on the next page, this page will send this file as an attachment in an email id. Can I call a function in another file and pass that file to that function? Some people think they are passing the stream to a function. (I'm not sure.) Can anyone guide me on this?
a source to share
You shouldn't transfer the file, it's better to process it in the background.
- save file
- put some id (worst case path) into session
- redirects the user to the next step (process.php)
Better to review and refactor the code if necessary to do the processing in one step. This way, you can avoid half-finished things, entering the processing pipeline in the middle, and similar common problems with processing multi-page forms.
a source to share
If you are trying to email a file to someone, PHPMailer ( http://phpmailer.codeworxtech.com/index.php?pg=methods ) has an addAttachment function that works very well.
If you are just trying to process the file in some way, file_get_contents will get the contents of the file as a string, which can be useful if the text is. However, you need to be careful that this is a small file, otherwise you will end up quickly.
a source to share