I have an input field for image upload in my view:
<input type="file" class="form-control" name="image">
I have created folder uploads in my public folder and in my Controller I am trying to upload a file like this:
$path = $request->file('image')->store('uploads/', 'public');
When I submit the form and upload an image nothing gets uploaded to the folder uploads and I get the error:
SQLSTATE[HY000]: General error: 1364 Field 'image' doesn't have a
default value
Have you try to put enctype and files on your form ->
enctype="multipart/form-data" files="true"
Related
I want to create folders using flask to store in azure blob . I need help to write the code in flask to store all the files of a registration page to a folder and that folder to be uploaded in azure blob storage.
I want to create folders for every user at register time. So how can I create a simple empty folder at particular path in flask.
i tried uploading the files from the web page to the azure blob storage and all files are getting uploaded.
but i want a separate folder to every single user who registers and this folders to be uploaded in the blob storage
This is the code of app.py to upload the files to blob storage:
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in allowed_ext
#app.route('/upload',methods=['POST'])
def upload():
if request.method == 'POST':
files = request.files.getlist('file')
for file in files:
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(filename)
blob_client = blob_service_client.get_blob_client(container = container, blob = filename)
with open(filename, "rb") as data:
try:
blob_client.upload_blob(data, overwrite=True)
msg = "Upload Done ! "
except:
pass
os.remove(filename)
return render_template("dashboard.html", msg=msg)
This is the html code of the files to be uploaded:
<form action="/upload" method="POST" enctype="multipart/form-data">
<div><label>Bank Statement*</label><input type="file" name="file" ></div>
<div><label>Affidant of support in case of someone sponsoring the education*</label><input type="file" name="file" ></div>
<div><label>Test of English Fulency- Duolingo/GRE/IELTS/TOEFL/OTHERS*</label><input type="file" name="file"></div>
<div><label>2022-23 River Certificate of finances for international students*</label><input type="file" name="file" ></div>
<hr>
<div class="button">
<input type="submit" name="upload" value="Upload" class="btn btn-success">
</div>
{{msg}}
</form>
I am saving some images which created & upload by CKEditor in my Laravel application and it getting saved properly. But when I want to edit the content, sometimes I am getting the content from DB and load it into CKEditor.
But Most of the cases, the page loading & loading ..... And The content not loads. Sometimes loads properly, but see the string as the attached image below.
How to solve this error!!
<textarea name="long_desc" class="form-control" id="summernote" rows="20">{{ $portfolio_data->long_desc}}</textarea>
<textarea name="long_desc" class="form-control" id="summernote" rows="20">{{ $portfolio_data->long_desc}}</textarea>
you can use {!! !!} for loading page content in blade engine in laravel instead of {{ }}
write like this:
<textarea name="long_desc" class="form-control" id="summernote" rows="20">{!! $portfolio_data->long_desc !!}</textarea>
I am trying to upload a file but getting error "The specified selector does not match a file input element", I know testcafe requires input type="file" for uploading files, But as we are reusing our custom component for file uploads where we are giving input type="url" It's not working with testcafe.
Here is the java script/HTML code
<input name="images" accept="image/*" type="url" class="form-control col-11 false" value="">
And I am trying to access the css selector like this
const click_add_image=Selector('input[name="images"]')
const add_image=Selector('input[name="images"],input[inputtype="url"]')
test
('add images', async t=>{
await t
.click(click_add_image)
.wait(2000)
.setFilesToUpload(add_image,[
'./_uploads_/Share_Knowledge.png'
])
I am getting error The specified selector does not match a file input element
I only find the file reading API on the server side. How should I read a file on the client side, with a filter dialog?
Thanks!
You can use an HTML file input with an accept attribute to restrict the type of file:
<input id="fileSelect" type="file" name="file" accept="image/*">
Then you can listen for the user selecting the file with a change event:
Element fileSelect = query("#fileSelect");
fileSelect.onChange.listen( (event) => print('${event.target.files[0].name}'));
event.target.files is a FileList object.
I have the follwing code
<form enctype="multipart/form-data" action="upload.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>
<?php
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
?>
my page is in http://local.host/nausal/upload.php
now I am having the follwing error though i have created a folder in site with name upload.
Notice: Undefined index: uploaded in C:\wamp\www\Nausal\upload.php on line 15
Notice: Undefined index: uploaded in C:\wamp\www\Nausal\upload.php on line 17
Sorry, there was a problem uploading your file.
If the form is a part of upload.php too, you need to encapsulate the PHP-code and first check if $_FILES is not empty, otherwise you will always get a Notice if you only want to display the form.
<?php
if(!empty($_FILES))
{
//your PHP-code here
}
?>
<!-- your form here -->
Khan sb Place this code in file
called upload.php
create a folder called upload where
you created upload.php
change echo "The file ". basename(
$_FILES['uploadedfile']['name']). "
has been uploaded"; to echo "The
file ". basename(
$_FILES['uploaded']['name']). " has
been uploaded";
This will upload file successfully. First time when upload.php is uploaded there is no file selected so you will see some errors. But after you select a file and click upload you will not see any error. To avoid this error do as suggested by Dr. Molle