PDA

View Full Version : Simple FTP check: Not a newbie but no expert either.



robertbruce
03-04-2010, 05:06 PM
Hello,

I would like a simple file upload system where the user:
clicks on the "choose a file to upload button"
selects a file and clicks submit button.
The file is uploaded to my server via ftp.

Once the user has selected a file I would like them to have the option of either changing their mind and choose another file if they make a mistake or clicking on submit.

http://www.internalarts.co.uk/upload.jpg

I can configure the ftp using the plugin but am stuck on how to check whether a file has been selected or not so if no file has been selected the user cannot submit.

I am also struggling to find a decent progress bar, so when the upload is complete the page jumps to another. (files around 50 to 100mb)


My code is as follows for:



"choose a file to upload" button (on_click code)
----------------------------------------------------

-- defines for table and text file if a file is selected
string_uploader = "abletoupload";
my_uptable = {string_uploader};

--open browser and select file to upload
archive_files = Dialog.FileBrowse(true, "Files to Add", _DesktopFolder, "All Files (*.*)|*.*|", "", "dat", false, false);

-- Check to see if an error occurred, or the user cancelled.
if (archive_files[1] ~= "CANCEL") and (archive_files ~= nil) then

-- create a text file if a file is selected
TextFile.WriteFromTable("AutoPlay\\Docs\\upload.txt", my_uptable, false);
end



--these are for keeping the files the same names and extensions

tFile = String.SplitPath(archive_files[1]);
sName = (tFile.Filename);
sExt = (tFile.Extension);
sFileName = String.Concat(sName,sExt);




"submit" button (on_click code)
------------------------------------------------------

-- Checks to see if a particular file exists.
are_ya_there = File.DoesExist("AutoPlay\\Docs\\upload.txt");

-- If the file does not exist, display a message notifying the user.
if are_ya_there == false then
result = Dialog.Message("Notice", "Please choose a file to upload", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
else
FTP.Upload(archive_files[1], sFileName, nil)
end



So the strategy was to create a text file "upload.txt" once the user has selected a file and then check that this text file exists when clicking on the submit button to allow the upload. Does not work, the text file is never created (admin rights are full for vista)

The progress bar is a mystery at the moment.

Would appreciate any help.

Rob

Scriptonite
03-04-2010, 07:35 PM
Here is a very simple FTP example. There are other more advanced examples on the forum if you need to get more in depth. You don't need to write to a text file, this will upload multiple files selected at once. You can use a listbox to add the files to for the user to see the files selected. Hope this helps.