This is a pretty simple question. I just need to know if I'm using movefile() correctly, because the file is not being moved. The npcserver has rights to all the needed folders.
This is a serverside file-checking script, using Graal's personaluploads feature. The movefile() functions are located in the conditional checks.
PHP Code:
function onActionServerside() {
// Get personaluploads directory and filename
temp.dir = player.getPersonalUploadFolder();
temp.folder.loadfolder(temp.dir @ "*", 0);
temp.file = temp.folder[0];
// Establish extension and header whitelists
temp.extensions = {"gif", "png"};
temp.headers = {"GIF8", "PNG"};
// Establish folders
temp.bodyfolder = "levels/graphics/player/bodies/";
temp.headfolder = "levels/graphics/player/heads/";
// Extract file extension and header
temp.fileext = temp.file.tokenize(".")[1];
temp.rawfilehead.loadlines(temp.dir @ temp.file);
temp.filehead = this.analyzeheader(temp.rawfilehead[0], temp.headers);
// Check if file extention is in whitelist
if(temp.fileext in temp.extensions) {
// If true, check if file header is in whitelist
if(temp.filehead != false) {
// If true, move file to correct directory, based on file name
if(temp.file.starts("valp") && temp.file.pos("head") => 0) {
movefile(temp.dir @ temp.file, temp.headfolder);
}
else if(temp.file.starts("valp") && temp.file.pos("body") => 0) {
movefile(temp.dir @ temp.file, temp.bodyfolder);
}
else {
// If file is not named correctly, delete it.
deletefile(temp.dir @ temp.file);
}
}
else {
// If false, stop script: this file is not allowed
deletefile(temp.dir @ temp.file);
return;
}
}
else {
// If false, stop script: this file is not allowed
deletefile(temp.dir @ temp.file);
return;
}
}
function analyzeheader(header, whitelist) {
for(temp.i: temp.whitelist) {
if(temp.header.pos(temp.i) => 0) {
return temp.i;
}
}
return false;
}