12 #include <boost/filesystem.hpp>
17 #include <gdcore/gdCore.h>
28 void* hndl = dlopen(
"libwt.so", RTLD_NOW | RTLD_GLOBAL);
30 fprintf(stderr,
"cannot load libwt.so shared library! %s\n", dlerror());
39 : WContainerWidget(parent), m_pFU(0)
46 WContainerWidget::load();
48 m_dialog->addStyleClass(
"WsFileUpload");
50 m_dialog->contents()->addWidget(
new WText(
"Upload a file with a maximum size of 8Mb"));
51 m_pFU =
new WFileUpload();
52 m_pFU->setProgressBar(
new WProgressBar());
57 WPushButton* cancel =
new WPushButton(
"Cancel ",
m_dialog->contents());
60 WApplication::instance()->log(
"notice") <<
"WsFileUpload::load : end !";
76 string internal = wApp->internalPath();
77 boost::algorithm::replace_all(
internal,
"/FileUpload",
"");
78 wApp->setInternalPath(
internal,
false);
84 std::string sCurUrl = wApp->internalPath();
85 std::string sWithoutPrefix =
WsApp->WsModules().pathWithoutPrefix(sCurUrl);
88 std::string sCurPath = m_sDocumentRoot + sWithoutPrefix;
90 if ( gdcore_isPathFile(sCurPath) )
91 sNewFile = boost::filesystem::path(sCurPath).parent_path().string() +
"/" +
m_pFU->clientFileName().toUTF8();
93 sNewFile = sCurPath +
"/" +
m_pFU->clientFileName().toUTF8();
94 if (exists(sNewFile)) {
95 LOG(
DEBUG) <<
"WsFileUpload::doUploaded(): sNewFile already exist " << sNewFile;
98 result = WMessageBox::show(
"Error",
"File already exist in current directory. Replace ?", Ok | Cancel);
102 string internal = wApp->internalPath();
103 boost::algorithm::replace_all(
internal,
"/FileUpload",
"");
104 wApp->setInternalPath(
internal,
false);
109 boost::filesystem::copy_file(
m_pFU->spoolFileName(), sNewFile, copy_option::overwrite_if_exists);
112 boost::algorithm::replace_first(sNewFile, m_sDocumentRoot,
"/Edit");
114 std::string newNode = sNewFile;
115 boost::algorithm::replace_all(newNode,
"/Edit",
"");
116 boost::algorithm::replace_first(newNode,
"//",
"/");
117 boost::algorithm::replace_first(sNewFile,
"//",
"/");
118 LOG(
DEBUG)<<
"WsFileUpload::doUploaded(): will now insert node "<<newNode;
122 wApp->setInternalPath(sNewFile,
true);
123 }
catch (boost::filesystem::filesystem_error& e) {
124 wApp->log(
"ERROR") <<
" WsFileUpload::doUploaded() cannot move " <<
m_pFU->spoolFileName() <<
" to " << sNewFile <<
" error = " << e.what();
130 wApp->log(
"notice") <<
" WsFileUpload::doFileTooLarge() : size " << nSize;
154 pFU->
outOptions(
"WsModFileUpload::createContents()");
170 return "WsModFileUpload wittyShare module";
void WsModFileUploadInit(void)
WsFileUpload(Wt::WContainerWidget *parent=0)
CTor.
const std::vector< WsOption > & options() const
Get all options.
WsEditorWidget * createEditor(Wt::WContainerWidget *parent=0) const
Create the contents for an editor (create a view of options).
Interface that provides differents methods for accessing the FsTree as well as other features...
std::string description() const
Return the description of the module.
void doFileTooLarge(int64_t nSize)
Wt::WWidget * createContents(Wt::WContainerWidget *parent=0) const
Create the contents.
const std::string getRootPath()
return the root path of the filesystem tree, example : /var/www/demo_site
void outOptions(const std::string message)
Output all options.
int createNode(const string &path, NodeType type)
create a directory or File. If the node is a WsDirNode than it will be only accessible to the Admin a...
#define WsApp
Define a shortcut to the application instance.
void setOptions(const std::vector< WsOption > &vOptions)
Set all options.
Wt::WWidget * createAdmin(Wt::WContainerWidget *parent=0) const
Create the contents for an administrator.
Wt::WWidget * createContentsMenuBar(Wt::WContainerWidget *parent=0) const
Create the functionalities.