Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
6
Erster Beitrag:
vor 3 Jahren, 5 Monaten
Letzter Beitrag:
vor 3 Jahren, 5 Monaten
Beteiligte Autoren:
Joel, Fabrice Harari

[WB19] Trying to create a folder & upload file to server

Startbeitrag von Joel am 03.03.2015 10:21

Hi everyone -

I'm trying to copy files to a directory on my server. The code is not throwing any errors, but it's not creating the directory or copying the file either.

"www.MartialArtsForAmerica.net" is pointed at the webroot. I know that works because if I type this into a browser: "www.MartialArtsForAmerica.net/mafa/mafa_members/AMA/Library/Images/book.jpg" it brings up the image. (I created the directory and put the image there manually)

I've spent over 3 hours on this and can't think of anything else to try. Can anyone see what I'm doing wrong - or have a better way to do this?

gpoDB:m_sStudioID = "AMAPDTEST"
sImageDir is string = "/Library/Images/"
gpoPrj:m_sStudioDir = "www.MartialArtsForAmerica.net/MAFA/MAFA_Members/"+gpoDB:m_sStudioID

// Retrieves the file name on the user computer
sSelectedFileName = UploadFileName(EDT_Upload, False)
sSelectedFileName = fExtractPath(sSelectedFileName,fFileName+fExtension)

// Make Directory on Server if doesn't exist
IF fDirectoryExist(gpoPrj:m_sStudioDir+sImageDir) = False THEN
fMakeDir(gpoPrj:m_sStudioDir+sImageDir)
END

//Copy File to server
sCopiedFileName = UploadCopyFile(EDT_Upload, gpoPrj:m_sStudioDir+sImageDir, sSelectedFileName)
sCopiedFileNameWithPath = gpoPrj:m_sStudioDir+sImageDir+sCopiedFileName

Antworten:

Re: [WB19] Trying to create a folder & upload file to server

Hi Joel

There are two problems with your code:

1. fMakeDir(gpoPrj:m_sStudioDir+sImageDir)
fmakedir expect a DIRECTORY... You are passing a URL to it... And that can not work. Yes, the URL point to the directory in question, but only when going through a browser+server link, which fmakedir clearly doesn't do.

So use instead frepweb() as the BASE of your directory then add the subdirectories (using \, not /)
Same thing goes for ANY FILE OPERATION (copy in your case...)

2. It's not because you can copy a file by hand in a directory that webdev will be able to do the same thing... Any webdev session is executed under a special user (generally IUser, for Internet User, but you'll have to verify in your server setttings). This user have very limited rights, for evident security issues, and you'll have to make sure that it has WRITE/DELETE permission on the appropriate directories where you want to work on your server

Best regards

von Fabrice Harari - am 03.03.2015 10:56

Re: [WB19] Trying to create a folder & upload file to server

Thanks Fabrice! I'm going to sit down and try that today. One more question - I need to be able to generate a URL to reference the photo to. something like "www.MartialArtsForAmerica.net\XYZ\XYZ\photo.jpg for using Tinymce to drop a image into a html control.

When trying to drop an image into the control, the html editor only gives me the option of using a URL to the photo. I guess I'd have to reference the project directory on the server, right?

How would you suggest doing this?

Thanks -

von Joel - am 05.03.2015 13:22

Re: [WB19] Trying to create a folder & upload file to server

Hi Joel

that part is quite easy...

You do know what URL matches what directory... So, you store the URL of the image directory in a string, the path of matching directory in a second one, and the name of the file itself in 3rd one...

By example:
sURL
sDirectory
sFileName

Of course, sURL AND sDirectory both end with the appropriate separator (/ or \)

at that point, if you work on the file, you use sDirectory+sFileName, and if you work on the URL, your use sURL+sFileName

Best regards

von Fabrice Harari - am 05.03.2015 14:51

Re: [WB19] Trying to create a folder & upload file to server

Great! Thanks!

von Joel - am 05.03.2015 19:18

Re: [WB19] Trying to create a folder & upload file to server

Hi again Fabrice -

Ok - I've got all that working, but, I just found out there's no "Copy to Clipboard" function in WebDev.

So the plan was to: Click on an image in the looper, copy the created url to the server to the clipboard, then the user would put the cursor in the HTML editor's image url field and paste it in there.

I'm stuck. Any way around this?

von Joel - am 06.03.2015 17:57
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.