What’s the best way to create a single-file upload form using PHP?

File Upload Tutorial HTML <form enctype=”multipart/form-data” action=”action.php” method=”POST”> <input type=”hidden” name=”MAX_FILE_SIZE” value=”1000000″ /> <input name=”userfile” type=”file” /> <input type=”submit” value=”Go” /> </form> action.php is the name of a PHP file that will process the upload (shown below) MAX_FILE_SIZE must appear immediately before the input with type file. This value can easily be manipulated on the … Read more

Rails 3 – upload files to public directory

a. Form <%= form_for :file_upload, :html => {:multipart => true} do |f| %> <%= f.file_field :my_file %> <%= f.submit “Upload” %> <% end %> b. controller def file_upload require ‘fileutils’ tmp = params[:file_upload][:my_file].tempfile file = File.join(“public”, params[:file_upload][:my_file].original_filename) FileUtils.cp tmp.path, file … # YOUR PARSING JOB FileUtils.rm file end But you can parse just tempfile, so … Read more

Upload DOC or PDF using PHP

Don’t use the [‘type’] parameter to validate uploads. That field is user-provided, and can be trivially forged, allowing ANY type of file to be uploaded. The same goes for the [‘name’] parameter – that’s the name of the file as provided by the user. It is also trivial to forge, so the user’s sending nastyvirus.exe … Read more

How do you upload a file to an FTP server?

Use the FTPClient Class from the Apache Commons Net library. This is a snippet with an example: FTPClient client = new FTPClient(); FileInputStream fis = null; try { client.connect(“ftp.domain.com”); client.login(“admin”, “secret”); // // Create an InputStream of the file to be uploaded // String filename = “Touch.dat”; fis = new FileInputStream(filename); // // Store file … Read more

Can anyone give me an example for PHP’s CURLFile class?

There is a snippet on the RFC for the code: https://wiki.php.net/rfc/curl-file-upload curl_setopt($curl_handle, CURLOPT_POST, 1); $args[‘file’] = new CurlFile(‘filename.png’, ‘image/png’, ‘filename.png’); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $args); You can also use the seemingly pointless function curl_file_create( string $filename [, string $mimetype [, string $postname ]] ) if you have a phobia of creating objects. curl_setopt($curl_handle, CURLOPT_POST, 1); $args[‘file’] = … Read more

Upload and POST file to PHP page with Java

Even though the thread is very old, there may still be someone around looking for a more easy way to solve this problem (like me :)) After some research I found a way to uplaod a file without changing the original poster’s Java-Code. You just have to use the following PHP-code: <?php $filename=”abc.xyz”; $fileData=file_get_contents(‘php://input’); $fhandle=fopen($filename, … Read more