PHP File upload redirect - php

Ok, this is might sound like a security hole but let's ignore that for a while. I need to allow users to upload a file to my website but I want to be in control of generating that file. I have a form where I want the user to create the new file and then that file should be the one that is uploaded. Is there anyway I can subvert the file upload control so that instead of popping up the 'Open' dialog box, it pops up my form and then when the form is submitted, the new created file is the one that's uploaded with the control?
Alternatively, I figure I could just use a regular button and a bit of JavaScript to open up my form in a window but then I would need a way to automatically the file to the form to be uploaded when my external form closes.
Thanks for the help!

If you want to be in control of generating that file, why not just have the form submit all of the information required to generate the control, and then generate the file on the server?

Related

Codeigniter - How can I initiate the download of a file and reset the form to be used again

Using Codeigniter, I'm trying to do something basic.
The site has a form where users upload files for processing. After the files are processed, new files are created and saved in a zip file. Then I use $this->zip->download() to start the download.
But after that I can't do anything to refresh the upload form. And if I reload the view first, the download doesn't work.
All I want to do is upload the files, create the zip, download the zip and wind up with a clean upload form.
Any suggestions how to approach this?
I don't think you will be able to do it on the same page because of missmatched headers. You could try the following: when the zip is ready save it and name it some random/unique id/md5 anything and print the download link in the view with "click here to download your file" with target="_blank" param so it opens in a new tab. (usually browsers are smart enough that it will auto close it when you accept the file). And so you can reset the form in the view as well.
Another way could be with ajax and js i guess but that would be much longer to write.
Ps.: just dont forget to delete the files after x amount of time (if you dont need them)

Upload files automatically to an input file from a path

I got a DDBB with some paths from different files that I keep in a table. What I'm trying to do is the following:
You can click a button which gets all that paths and loads all the files to an input file just to send it as attached file via e-mail using a php script.
The thing is, I don't know if it is really necessary to take that step with jquery or is it possible to send it straight away using php?
If I understand correctly, you have file paths in DB, which is Backend, and when you create page view you are getting paths from DB by PHP still Backend, then you will put a hidden field etc. when a person click a button 'Frontend but dummy action' you want to load these files and send to backend again.
Logically;
If Client and Server are not discrete then this wouldn't be a reliable system, because you are not sure files are in the correct path which means will not be renamed, deleted.
If client and server are the same you don't need to make this with a file upload you already know you have the paths when user click the button ex : button submits the form with id/group_id 1, fetch paths by id or group_id and send by email.
But still you want to do something like that, Html5 has an api http://www.w3schools.com/jsref/dom_obj_fileupload.asp for it, beyond that you need to execute an applet to achieve this I think.

Drag and drop files to be uploaded when the form is submitted

I'm trying to implement drag-and-drop file selection for uploading files synchronously once the form is submitted. I know how regular file uploading works with HTML and PHP. And I want to be able to process the files in PHP alongside the ones in the $_FILES array.
I've done some research and looked at several plugins but pretty much all of them either upload files once they're dropped into the window or don't use conventional html forms.
Any kind of help like ideas, snippets or plugins would be appreciated.
Thank you!
It is impossible to set the files attribute of a file input via JavaScript for security reasons. See this jsfiddle.
So, you cannot select files for a file input via drag and drop, you have to select the files via the file input directly, by clicking on the 'browse files' button.
What you can do is to implement an onUpload method for the form, to upload the files when the user clicks the submit button, via AJAX. Then, when the uploads are completed, you submit the form with the other data.
See this fiddle to see how to upload files via AJAX. The code has the drag and drop processing and converting binary files into BASE64. You will need to create the AJAX bit by posting the data. To check if the files are done, create a function to be called with setInterval, to check if all the uploads completed.
Cheers,
Apoc

How to restrict file types for a user in a web browser

Hi i have a question that is almost like other questions but with a small but very important difference.
How can i restrict file types for user with a popup showed in the browser.
The standard file input of html can limit that with a command but it does not work in all browser so it is not an option.
I do not want to validate the file extension after the user has chosen a file but before that, when he is choosing.
Founded this http://demo.swfupload.org/v220/index.htm, but it uploads the file after the user has chosen it, i do not want to do that, i want to upload it after the user submits the form.
So the problem looks like this that there are some ways of not letting the user send a not valid file but they are not good because, one is that i validate after the user have chosen the file and the other is that i upload the file before the user submits the form.
I just want a simple thing to not letting to "chose" a not valid file, it does not matter if it will be made with java script or flash, just let it work.
maybe you have some ideas on how to do it because i searched the whole internet and did not found any solution.
Uploadify supports that feature and is very customizable. You should have no problems setting it up in a way that it uploads the file when the user submits.
you can put a condition on the action file of php where all the fields get by submit the page.at that time you can put validation for the file type. if the file type is not as you mentioned then redirect the error message and let user to make try again.
Thanks.
<input type="file" accept="text/html,image/jpeg">
Also: Mozilla`s doc
Not sure if that's what you're after, but Flash FileReference.browse() method has a FileFilter structure as an input argument, and there you can limit the types of files that the upload dialogue will show.
flash.net.FileReference

How can a user upload a résumé in Word or other common format and have it uploaded into my DB in PHP?

How does résumé upload work? I have a site in PHP and right now users can build their résumé line by line, because it is stored in db table. How can a user upload a resume in Word or other common format and have it uploaded into my db? Is it something to do with regex? Are there any scripts out there available that can do that?
Just trying to understand the process.
Thanks.
UPDATE:
BTW I looked around a bit and saw web-forms for resume creation -- I already have that. I need a user to be able to point webform to his/er resume, click SUBMIT and have that document input into db automagically.
Simply use the file uploading feature:
create a HTML page containing a <form> and a file input.
create a PHP script that receives the uploaded file
The process is simple: user selects a file to upload and the browser sends it to a PHP script designated by the action attribute of the <form> tag. After the file is uploaded into the server, you can do whatever you want with it.
PHP file upload tutorial
File uploading guidelines in PHP manual

Categories