PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → [WB19] Trying to create a folder & upload file to server
[WB19] Trying to create a folder & upload file to server
Débuté par Joel, 03 mar. 2015 11:21 - 5 réponses
Posté le 03 mars 2015 - 11: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: "

" 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 = "<a class="ExternalLink" rel="nofollow" target="_blank" href="http://www.MartialArtsForAmerica.net/MAFA/MAFA_Members/"+gpoDB:m_sStudioID">www.MartialArtsForAmerica.net/MAFA/MAFA_Members/"+gpoDB:m_sStudioID</a>

// 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
Posté le 03 mars 2015 - 11:56
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
Posté le 05 mars 2015 - 14:22
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 "<a class="ExternalLink" rel="nofollow" target="_blank" href="http://www.MartialArtsForAmerica.net\XYZ\XYZ\photo.jpg">
<img src="http://www.MartialArtsForAmerica.net\XYZ\XYZ\photo.jpg" border="0" class="ExternalImage" onerror="OnImageLoadFailure(this);"/>
</a> 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 -
Posté le 05 mars 2015 - 15:51
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
Posté le 05 mars 2015 - 20:18
Great! Thanks!
Posté le 06 mars 2015 - 18:57
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?