Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Uploadfile();? (https://forums.graalonline.com/forums/showthread.php?t=134266193)

Gunderak 04-07-2012 08:49 AM

Uploadfile();?
 
Does this function work serverside?
I have a system in which you can upload files to a webserver then on the server it gets all the files by doing requesturl on a php script.
It then has a for loop which gets all the files and is supposed to upload them.
It just returns: Script: Function uploadfile not found at line 15 in script of UploadSystem.
Any idea's?

Edit: I have done some research.
My question is now: Is it possible to upload a file from a URL to a GServer?

I have tried
PHP Code:

//#CLIENTSIDE
function onCreated(){
  
Upload();
}
function 
Upload(){
  
requestText("folder""PERSONAL");
  
uploadfile("http://www.wr3ckless.net/corinthia/uploads/shop_hatshop.nw");


aswell, with no luck.

Admins 04-07-2012 11:46 AM

You can either let the user upload a file with selectfileforupload() (local files) or in your case you call requesturlasgamefile() on server side.

cbk1994 04-07-2012 01:07 PM

To clarify what Stefan said: no, and even if it did exist serverside, that's not how it's used. You're going to need to either use requesturlasgamefile, as Stefan recommended, or load the file into a variable via cURL or requestHTTP and use saveString to some folder that is in folder config. Look at my graphics uploader in the code gallery for an example.

Gunderak 04-07-2012 01:36 PM

I think I'll go with requesturlasgamefile();
I'm not on my PC atm but I take it that it works something like this?
PHP Code:

  temp.file requesturlasgamefile("http://blahblah/something/content.png");
  
temp.file.savestring("uploads/"@temp.file0); 

And is there any function in GS2 similar to PHP like move(); or move_uploaded_file?

The uploading from the webserver works, but for some strange reason when I write /find filename.nw it can't find it, and YES I have added level uploads/*.nw to the serveroptions.

Gunderak 04-07-2012 04:59 PM

Well now I'm having an issue saving the string to a file..
It worked before but now it has stopped working o.o
Here is the part that is problematic.
PHP Code:

function GetFiles(){
  
this.ply player.account;
  
temp.req requesturl("http://wr3ckless.net/corinthia/getfiles.php");
  
thiso.catchevent(req"onReceiveData""onGot");
}
function 
onGot(req){
  
temp.url "http://www.wr3ckless.net/corinthia/";
  
temp.dat req.fulldata;
  for(
temp.0temp.dat.size(); temp.++){
    
temp.file requesturlasgamefile(url@dat[f], dat[f], 0false);
    
temp.dat temp.file.fulldata;
    
temp.dat.savestring("levels/"@dat[f], 0);
    
sleep(1);
  }


It isn't creating a file, yet before it was.
And yes the control NPC has rw rights.

Tigairius 04-07-2012 10:34 PM

Quote:

Originally Posted by Gunderak (Post 1691356)
Well now I'm having an issue saving the string to a file..
It worked before but now it has stopped working o.o
Here is the part that is problematic.
PHP Code:

function GetFiles(){
  
this.ply player.account;
  
temp.req requesturl("http://wr3ckless.net/corinthia/getfiles.php");
  
thiso.catchevent(req"onReceiveData""onGot");
}
function 
onGot(req){
  
temp.url "http://www.wr3ckless.net/corinthia/";
  
temp.dat req.fulldata;
  for(
temp.0temp.dat.size(); temp.++){
    
temp.file requesturlasgamefile(url@dat[f], dat[f], 0false);
    
temp.dat temp.file.fulldata;
    
temp.dat.savestring("levels/"@dat[f], 0);
    
sleep(1);
  }


It isn't creating a file, yet before it was.
And yes the control NPC has rw rights.

You'll need to at least tokenize req.fulldata in order to access it as an array. Here's an example:
PHP Code:

  temp.dat req.fulldata.tokenize(","); 

And even doing that won't guarantee that it'll work. It's just one thing I noticed. Also I don't know why you're using the same variable name inside of the for loop as the array that you're looping through.

Gunderak 04-08-2012 04:44 AM

Now the first file will save the strings but then the rest of the files the file.fulldata returns as null o_o

Gunderak 04-09-2012 10:37 AM

@unknown I have tried to debug it.
No need to neg rep me, a reply would of done the job ;)


All times are GMT +2. The time now is 04:05 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.