I am new to WT, i am trying the upload file example . The code works fine when i click the send button the file progress bar runs to 100% but i am not sure where it is uploaded ? can we define to upload in certain path..
class HelloApplication: public WApplication {
public:
HelloApplication(const WEnvironment& env);
private:
WPushButton *uploadButton;
Wt::WFileUpload *fu;
void greet();
};
HelloApplication::HelloApplication(const WEnvironment& env) :
WApplication(env) {
root()->addStyleClass("container");
setTitle("Hello world"); // application title
fu = new Wt::WFileUpload(root());
fu->setFileTextSize(50); // Set the maximum file size to 50 kB.
fu->setProgressBar(new Wt::WProgressBar());
fu->setMargin(10, Wt::Right);
// Provide a button to start uploading.
uploadButton = new Wt::WPushButton("Send", root());
uploadButton->setMargin(10, Wt::Left | Wt::Right);
// Upload when the button is clicked.
uploadButton->clicked().connect(this, &HelloApplication::greet);
}
void HelloApplication::greet() {
fu->upload();
uploadButton->disable();
}
WApplication *createApplication(const WEnvironment& env) {
return new HelloApplication(env);
}
int main(int argc, char **argv) {
return WRun(argc, argv, &createApplication);
}
A WFileUpload will fire a signal (uploaded()) when the file is completed. Then look at spoolFileName() to get the filename of the file on your local disk. Listen on fileTooLarge() too, since it will inform you that the upload failed.
The manual of WFileUpload comes with a lot of information and a code example: http://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WFileUpload.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With