Uploading a .gz file VIA html form - php

I've been searching google abit and could not find anything that would help! I have a customer that would like to upload large CSV files of products (A right pain as there 150mb plus uncompressed).
I Noticed that he gets the files compressed from the wholesaler with gz (down to 6mb). I've been trying to upload the gz via the admin form I've created for him but the $_FILES global is empty when submitting (this is after it has gone through the upload to the tmpdir)
everything works fine if i upload the uncompressed csv (as in the $_FILES global is not empty), So i'm guessing the server is blocking the file? but i can't find anything about this and checking out other upload scripts people are allowing the extension.
Form Below:
<form action="/admin.php?current_page=new_upload" method="post" enctype="multipart/form-data">
<label for="csvFile">CSV File: (*)</label>
<input class="form-control" type="file" required name="csvFile" id="csvFile" />
<input class="btn btn-success" id="subBtn" type="submit" value="Upload CSV to Site" />
</form>
Getting tmp_name here which is empty when trying to upload gz file (first line on the file):
$fn = $_FILES['csvFile']['tmp_name'];
put a var_dump($_FILES) at the top of the file and its completely empty, so its getting lost before hitting any of the script
But no issues if I upload a .csv file

So i finally gave in and uploaded the huge uncompressed file, which failed, i then GZ'd the sample data and it worked fine, so it must be an issue with file size, and even though the gz is only 6mb (we've set the limit to 150mb) the server must be reading the file at its actual size before even touching the script.
I'll be playing around with the server settings, but thanks for looking anyway!

Related

Have file automatically upload to server when .php is launched

I'm trying to write code in php so that when the .php file is opened, it automatically uploads from a specific file address on my windows computer to the localhost server.
This is my attempt but I'm not sure I fully understand how to do this without using an HTML form where the user specifies the file they want to upload.
<?php
$target = 'UPLOADED_FILE.csv';
move_uploaded_file('C:\Users\Ken.Feier\Desktop\temp\REPORT.csv', $target);
?>
I want the code to take the REPORT.csv file from my personal computer and upload it to our server with the file name UPLOADED_FILE.csv
UPDATE: I see that my problem will not be solved with php. Can anyone recommend any other solution involving Filezilla or any other FTP that can be automated?
That's not how it should be done.
You need a page with a html form, which will send the data to server on submit. Note that the file could be stored on your personal.
Form code e.g.
<form method="post" action="destination.php" enctype="multipart/form-data">
<input type="file" name="filename" />
<input type="submit" value="upload" />
</form>
Then, on the server, you can use the $_FILES['filename'] which contains your file's infos. Note that when a file is uploaded to the server, it's stored in the tmp folder, which is temporary, so you have to move your file to a persistent directory with move_uploaded_file(); (move_uploaded_file Docs)
E.g:
<?php
$file = $_FILES['filename'];
move_uploaded_file($file['tmp_name'], '/new/destination/for/the/filename.php');

read contents of file forms php

I'm trying to create a local php script that lets the user select a file, then outputs the file contents. I don't want to save the file anywhere, just read its contents. I've been reading guides on file input types and this is the examples I'm seeing:
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
My question is, since I don't want to upload the file anywhere, just read it's contents (this script is personal and runs locally so I'm not worried about security), is there a way to extract the file contents from the file selected in the <input type="file"> without putting this in a form? I'm new to this stuff and want to make it as simple as possible to just read the file's content.
PHP is a server side language, whichs means you'd need to "upload" the file in order to process it, even if web server is local, the browser needs to send the file to the PHP script
Here is a guide for file uploads via POST:
http://php.net/manual/en/features.file-upload.post-method.php
In order to get the contents of the script in a variable, you'd have to read the temporary file after the file has been uploaded through a form's post method:
$tmp_file = $_FILES['fileToUpload']['tmp_name'];
$contents = file_get_contents($tmp_file);

How to upload .ipa file to server in html?

I am able to upload other file types like .txt, .png, .apk using
<form action="index1.php" method="post" name = "mySuperForm"
enctype="multipart/form-data">
<input type="text" placeholder="Application Name" name="appname">
<input type="text" placeholder="Version Number" name="appversion">
Application File: <input style = "width:auto" type="file" name="file" id="file"><br>
</form>
But, when I try to upload a .ipa file, I can't grab the application name or version number on index1.php (the page I am posting to)using $_POST. However, if I upload a different file type, I can. It's as if nothing is getting posted if I try to upload an ipa file, like the html is failing on that line. I am using my localhost, wamp server. Any advice?
Without seeing your handling PHP, it's a bit difficult to diagnose, but here are a few potential items that may point you in the right direction:
Does the .IPA file exceed the *post_max_size* or *upload_max_filesize* as defined in your PHP configuration?
Try var_dump($_FILES); to see if your script is seeing the files there.
I think this is happening because the file is too big and the request is being truncated by the web server, so PHP would not be able to access any form fields because the request was not completed. How large is the ipa file? You might need to adjust your maximum post size. The default is usually 4 MB.

PHP ftp_put files are uploading, but I cannot find them on my server

so I am the webmaster/in charge collecting the files for a music video contest. The problem is I only know HTML, CSS, limited PHP, and some Actionscript 2. I need to be able to allow people to upload large files to my server (the videos they are submitting) but I am unable to find a way to do that. I was wondering if anyone had any suggestions of an upload system that work work for me. I have tired PHP's ftp_put but the files seem to be too large for it to handle. Thanks
I'm not sure if this will work for very large files, but I do some image uploading using a form and file inputs like so:
HTML
<form method="post" action="upload.php">
<input type="file" name="file" />
</form>
PHP
move_uploaded_file($_FILES['file']['tmp_name'], $server_path . $new_file_name);
You can also upload multiple files like so:
HTML
<form method="post" enctype="multipart/form-data" action="upload.php">
<input type="file" name="files[]" />
<input type="file" name="files[]" />
<input type="file" name="files[]" />
</form>
PHP
for ($i = 0; $i < count($_FILES['images']['error']); $i++)
{
move_uploaded_file($_FILES['file']['tmp_name'][$i], $server_path . $new_file_name[$i]);
}
I know for example youtube, as well as facebook have a process that uploads the files by parts ... but I don't know how it happens.
Another way would be to create an ftp account for each user and then they can use a program like filezila.
The other way, I think it would be an application in Java.
large files can also be handled by ftp_put, check your settings for upload_max_filesize, post_max_size, max_execution_time, max_input_time, and memory_limit in your php.ini file. These could all affect your file uploading abilities.
The problem with PHP uploading is that typically there's a file size limit and there's a server timeout limit as well, as in if the script is running for so long, it will time out. This becomes a problem in uploading larger files. If you can modify these settings yourself on your server then I suggest you try SWFUpload

HTML Upload Form will only upload files found in the directory of the PHP file

I have an image uploader that uses the imgur.com API and jQuery's .ajax() function to upload images to their servers. However, if I browse for an image using the <input type="file"/> element of the form, it will only be successful in uploading an image if the image file is found in the same directory as the page.php file that the form is found in (shown below). How can I allow the form to upload images from any directory on my computer?
page.php:
<form action="page.php" method="post">
<input type="file" name="doc" id="doc" /><br/>
<input type="image" src="go.gif" name="submit" id="submit" />
</form>
You've forgotten the enctype="multipart/form-data" attribute on your form tag, for one. Without that, file uploads generally don't work too well.
Beyond that, the server won't really care what directory you're uploading FROM, especially under PHP. The uploaded copy on the server is stored with temporary filename ($_FILES['file']['tmp_name']) that has absolutely nothing to do with the directory/filename on your computer.
Once it's on the server, you'll have to actually move that temporary file somewhere else, as PHP will auto-delete it once the script terminates and you've not handled it yourself. move_uploaded_file() is what's generally used to take of that process.
Perhaps this is the only folder with write-permissions.
I guess it is jquery that is doing the actual posting to http://imgur.com/api/upload as the form is just posting to itself, so my guess is that jquery / javascript can only read files in your web-space and not on your whole hard-drive.

Categories