I'm currently working on a photoalbum thing on my website and was wondering is there is a way to upload files separately even though I selected multiple files for upload, let me explain:
<form method="post" action="upload.php" enctype="multipart/form-data">
<input name='uploads[]' type="file" accept="image/*" multiple>
<input type="submit" value="Send">
</form>
<?php
$y=count($_FILES['uploads']);
for($x=0;$x<$y;$x++) {
echo $_FILES['uploads']['name'][$x];
echo "<br>";
}
?>
So I've got these simple lines of code. And basically (As you can see) you can upload multiple files. But let's say that that my 'upload_max_filesize' is at 8M. I can only select 4 images of 2MB each to upload successfully, otherwise I overwrite the max upload size. My question is, is there a PHP way to keep the form structure the same but let the script handle one file at the time so I can upload 5.000 files from 5MB's each for example?
Related
I am trying to debug my front-end of a HTML/PHP web face and have run into an issue. Currently, the user is able to upload a file, which is then sent to a separate upload function (to process and upload their file to an AWS instance), and then redirects the user to another page.
On the page, I have two options for the user to click- the first of which unhides an option for the user to select and upload their file. This option uploads to the AWS instance and functions normally. The second option unhides some text about download/upload instructions, along with an option for the user to select and upload their file.
Both options do functionally the same thing, with only difference being the second option unhides some text in addition to revealing exactly the same button. Only the first option posts and uploads like normal; the second doesn't upload to the bucket and just returns 'zero' in plain text to the screen. Has anyone experienced anything like this and/or has any advice on how to fix it? Thanks!
Below are the two code snippets for the upload forms:
<form id="Site" method="POST" enctype="multipart/form-data">
<div id="file_input"><input id="files" type="file" name="file"/></div>
<label for="files">SELECT ZIP FILE TO UPLOAD</label>
<br>
<input type="submit" value="submit" name="submitSite">
</form>
and the one that doesn't work (exactly the same?)
<p> Download Instructions Go Here</p><br>
<form id="Site" method="POST" enctype="multipart/form-data">
<div id="file_input"><input id="files" type="file" name="file"/></div>
<label for="files">SELECT ZIP FILE TO UPLOAD</label>
<br>
<input type="submit" value="submit" name="submitSite">
</form>
And the POST function itself is:
<?php
session_start();
$_SESSION['Username'] = '';
$userID = $userID; // change this to be set in database
//set progress
$_SESSION['progress'] = 'upload_section';
'/survey_interface_shared_libraries/progress_emails/store_progress.php';
if (isset($_POST['submitSite'])) { // upload file
Please let me know if you need any further context!
I am trying to upload multiple files (tsv,csv) using PHP. The HTML and PHP script is written below. It works for me when running with XAMPP on Windows. However, on Ubuntu,when trying upload 2 files at a time (one is tsv, the other is csv) I can only upload one file at a time, but not two. I am not sure what the reasons are but it seems that there is something needed to be done with the server settings.
The code below won't work if I upload both tsv and csv but it works with other file types.
<form action='' method='post' enctype="multipart/form-data">
<input type='file' name='usrfile[]'/>
<input type='file' name='usrfile[]'/>
<input type='submit' name='submit'/>
</form>
<?php
if(isset($_POST["submit"])){
for($i=0;$i<=1;$i++){
move_uploaded_file($_FILES["usrfile"]["tmp_name"][$i],"upload/" . $_FILES["usrfile"]["name"][$i]);//upload the ecwave file to the upload/ folder
}
}
?>
Make a look at the manual.
There is a max_file_uploads setting, which restricts the number of allowed files per form.
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
I'm developing an image host and wish to have images uploaded to a separate server from my web content, eg: http://i1.mysite.com instead of http://mysite.com/uploads. But I'm having some trouble figuring out how to do that.
Say I have this form:
<form action="http://mysite.com/upload" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<input type="file" name="image" id="file_upload" />
<input type="submit" value="Upload" id="upload_submit" />
</form>
That will send an image file to /upload, where I can validate the file and save it, but that will be on the same server as the website is hosted, rather than a dedicated storage server. How can I achieve what I want without having the images uploaded on the same server as my web site?
I could always do:
<form action="http://i1.mysite.com/upload" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<input type="file" name="image" id="file_upload" />
<input type="submit" value="Upload" id="upload_submit" />
</form>
which would send the image file to another server, but then when the image upload is complete I'd be redirected to http:/i1.mysite.com/upload.
Anyone have any experience with this and can recommend a course of action? Thank you!
Don't upload to the image server. Such content-specific servers should be optimized for serving up content, and not have to deal with consuming content.
Let the upload form send to your main site's server. You can then use other protocols to transfer the uploaded file(s) to the image servers. rsynch, scp, etc... This way you have all your "control" code in one location, and don't have to worry about synching databases and whatnot between multiple servers - all the data is kept on your main server, and the image servers just passively spit out image data.
I would recommend decoupling these two ideas. First, upload the image to your servers and in a separate process (perhaps a scheduled cron) move the images to other server. You likely do not want the user waiting for two uploads to finish.
Like the others have said, what you're trying to do is not optimal. If you really want to continue to do this, I'd suggest having the form submit to a PHP script which then processes it and places the file where it needs to be and then saves whatever information to the database that is necessary. You'll need to evaluate the best protocol for the data transfer from one server to the other. You'll probably end up using Curl, which you can learn about here and here as well as the curl docs
You could upload the image to your image host, and have it redirect back to your website afterward. One way to do this would be to add hidden "success" and "failure" URL inputs to the form:
<form action="http://i1.mysite.com/upload" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<input type="file" name="image" id="file_upload" />
<input type="submit" value="Upload" id="upload_submit" />
<input type="hidden" name="success" value="http://mysite.com/success" />
<input type="hidden" name="failure" value="http://mysite.com/failure" />
</form>
The upload script on your image host would then redirect to the supplied URL after a successful upload:
<?php
.. handle uploaded file ..
if ($success) {
header ('Location: ' . $_REQUEST ['success']) ;
}
else {
header ('Location: ' . $_REQUEST ['error'] . '?message=' . $message) ;
}
?>
I want to upload the files to this address: http://chusmix.com/Imagenes/grupos and I'm trying with this simple this code but it doesn't work:
<form enctype="multipart/form-data" method="post" action="http://chusmix.com/Imagenes/grupos">
Please specify a file:<br>
<input type="file" name="datafile" size="40">
</p>
<div>
<input type="submit" value="Send">
</div>
</form>
Oddly enough, the first result of a Google search yielded this rather helpful tutorial. Why not read it?
Read the PHP manual chapter "Handling file uploads":
http://php.net/manual/en/features.file-upload.php
The way you think uploads work is not the way they work. The form posts to the script you want to handle the request, not the location you want the uploads to be. When you upload a file to Apache, it places that file in the temporary directory of the computer (in Linux, that's /tmp by default).
Your script has to move the file from the temp directory to wherever you want it to be. The manual has plenty of code showing you how.
Make sure the form is loaded via
http://chusmix.com/Imagenes
The browsers wont you allow to upload to a unkown website (Same origin policy).
Edit your form
<form enctype="multipart/form-data" method="post" action="/grupos">