I am getting this error when uploading a pdf file, any ideas?:
RuntimeException stream_socket_sendto(): A request to send or receive
data was disallowed because the socket is not connected and (when
sending on a datagram socket using a sendto call) no address was
supplied
form in view:
<form action="{{ route('press-files.store') }}" method="POST" enctype="multipart/form-data">
#csrf
<input type="file" name="pressFiles[]" multiple="multiple">
<button type="submit" class="btn btn-primary start">
<i class="pe-upload"></i>
<span>Start upload</span>
</form>
Controller:
public function store(Request $request)
{
$press_files = $request->all();
dd($press_files);
}
this is only happening on .pdf files - png's and jpegs all work.
Thanks for any help in advance
Add these lines in your .htaccess
php_value upload_max_filesize 30M
php_value post_max_size 30M
php_value max_execution_time 300
php_value max_input_time 300
It turned out to be due to file size. I will keep this question and answer incase anybody else requires it.
The .pdf I was using was 2.8 MB and this failed, I used a much smaller file ~125kb and this worked fine.
Related
I have an application in laravel 9, in my local environment I can upload images without problem (amazon s3), but in my deployment in heroku I get this error when trying to get the image I am sending.
<form action="/test-upload-file" method="POST" enctype="multipart/form-data">
#csrf
<input type="file" name="image" id="image">
<button type="submit">Upload File</button>
</form>
this is my function
Route::post("/test-upload-file", function (Request $request) {
$testFile = Storage::put('tests', $request->file('image'));
dd($testFile);
});
this is the error I am getting
The "" file does not exist or is not readable.
I just found the solution, it is for the PHP configuration of the server, just create a .user.ini configuration file in the /public folder.
post_max_size = 10M
upload_max_filesize = 10M
All of the files are available at http://gist.github.com/tonyahowe -- page.html, app.xql, upload.html, and form1.html. The app:upload function in appxql is at line 378.
I am trying to add an upload feature to my application here (http://nic.cerosia.org) and have been able to get the upload to work without integrating it into the whole application. Once I integrate it, I get a 400 error message, included below. I think the problem might be a controller issue, but I'm not sure?
I have added a simple link from the index to upload.html page, as follows:
<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="main">
<form enctype="multipart/form-data" method="post" action="form1.html">
<fieldset>
<legend>Upload Document:</legend>
<input type="file" name="file"/>
<button id="f-btn-upload" name="f-btn-upload" value="true" type="submit" class="btn btn-danger">Upload</button>
</fieldset>
</form>
</div>
That sends the upload file to form1.html, which basically figures out what to do with different form actions (it works with the first two options):
<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="main">
<div/>
<!-- if a query search -->
<div data-template="templates:if-parameter-set" data-template-param="query">
<div data-template="templates:include" data-template-path="search.html" class="col-md-12"/>
</div>
<!-- if a coursepack search -->
<div data-template="templates:if-parameter-set" data-template-param="f-btn-coursepack">
<div data-template="templates:include" data-template-path="coursepack.html" class="col-md-12"/>
</div>
<!-- if an upload -->
<div data-template="templates:if-parameter-set" data-template-param="f-btn-upload">
<div data-template="templates:include" data-template-path="success.html" class="col-md-12"/>
<div data-template="app:upload"/>
</div>
</div>
The app:upload is here:
declare function app:upload($node as node(), $model as map(*), $type as xs:string?) {
let $collection := '/db/apps/NiC/inReview/'
let $filename := request:get-uploaded-file-name('file')
(: make sure you use the right user permissions that has write access to this collection :)
let $login := xmldb:login($collection, 'public', 'public')
let $store := xmldb:store($collection, $filename, request:get-uploaded-file-data('file'))
return
<results>
<message>File {$filename} has been stored at collection={$collection}.</message>
</results>
};
I keep getting an error that I think has something to do with the controller, but I'm not sure. Can anyone help me figure out where the problem is? It may also be a templating issue?
Here's the error:
HTTP ERROR 400
Problem accessing /exist/apps/NiC/works/form1.html. Reason:
SAX exception while parsing request: Content is not allowed in prolog.
I don't know for sure, but I wonder if it is an issue with the templating framework reading the data from the request body and then it not being available in your app:upload function.
I wonder if we could test this, perhaps instead of checking for f-btn-upload which will be in the body of the HTTP request, you could instead check for a query-string parameter. If you change your form in the upload.html page to be like this:
<form enctype="multipart/form-data" method="post" action="form1.html?do-upload=true">
and the switch in your form1.html to be like this:
<div data-template="templates:if-parameter-set" data-template-param="do-upload">
Does that help you at all?
I'm trying to upload multiple files using Dropzone.js, but it acts like it's upload one file per one upload.
For example: I select 3 files, click on the OK button, Dropzone shows OK status (successful uploaded), but server side get 3 separate request with one file per each request.
I need to get all files as an array of files, can anybody help with this case?
Code:
<form id="my-awesome-dropzone" class="dropzone custom_bc" action="'.$_SERVER['PHP_SELF'].'">
<input type="hidden" name="action" value="file">
<div class="fallback"><input type="file" name="file" multiple></div>
<input type="hidden" name="object_id" value="'.$_REQUEST['object_id'].'">
<input type="hidden" name="est_id" value="'.$_REQUEST['est_id'].'">
<div class="dz-preview"></div>
</form>
I have also tryed to put [] in the name of <file>, but it doesn't help
<input type="file" name="file[]" multiple>
You need to set uploadMultiple to true.
var myDropzone = new Dropzone(
"#my-awesome-dropzone",
{
url: document.URL, // Set the url
paramName: "file",
uploadMultiple: true
}
);
When setting uploadMultiple to true, Dropzone automatucally concatenates [] to your file name. So you don't need to do that.
Is there a way to upload file using pure prototype and ajax. I've searched for it on google but did't got any satisfactory result. Can anyone please help me out??
The easiest way to get an "Ajax" file upload to work is to use a keyhole iframe as the target for your form:
<form action="handler/url" enctype="multipart/form-data" target="keyhole" method="post">
<input type="file" multiple name="user_file[]" />
<input type="submit" id="upload" value="Upload">
</form>
<!-- style the following to be tiny/hidden -->
<iframe id="keyhole" src="about:blank"></iframe>
The trick with this is to show a waiting indicator, and hide it after the upload is complete.
<div id="waiting" style="display:none"></div>
<script type="text/javascript">
$('upload').observe('click', function(evt){
$('waiting').show();
});
</script>
In your file upload handler, return a text/javascript header and the following script after a successful upload:
var waiting = top.document.getElementById('waiting');
if(waiting) waiting.style.display = 'none';
Naturally, this will only work if both endpoints are on the same server, owing to Same Origin Policy.
So I need a way of validating the sum total of multiple files being uploaded. I know this needs to be done on the client's side but I am not sure how to implement it. Here is the form I amusing:
<form action="upload.php" method="POST" enctype="multipart/form-data" >
<input type="file" name="image[]" multiple="multiple">
<input type="submit" value="upload">
</form>
You can do it in HTML5, something like:
var file = document.getElementById('fileToUpload').files[0];
// now you can get the size via:
var fileSize = file.size;