Jump to content




getting an uploaded file and converting[Not solved]


  • You cannot reply to this topic
15 replies to this topic

#1 Goof

  • Members
  • 751 posts

Posted 02 April 2014 - 02:30 PM

Hello

Edit: New problem in latest error comment Below... :(/>

In my topic in the Generals section about uploading files to my own webpage, I wanted to know how to do that, I got the answer,
but I've just edited the phpcode and it turns out that when textutils.urlEncode'ing files there appears to be some
something=\'something\'
all over the code where theres " ' " or ' " '...


How can i solve this?

current code
local args={...}
if #args < 2 then
  printError("Arguments must be:")
  printError("handle , fileName")
  return
end
local getorput = args[1];
local fileName = tostring(args[2]);
local fileHandle = fs.open(fileName, "r")
local sFile = fileHandle.readAll()
fileHandle.close()
sType="program"
local site = 'http://mywebsite.com/dev/upload.php'
local respons = http.post(site, 'RESPONSETYPE='..tostring(getorput)..'&POSTDATA='..textutils.urlEncode(sFile)..'&POSTTYPE='..textutils.urlEncode(sType)..'&POSTNAME='..fileName)
local response=respons.readAll()
response:gsub("[\']", "'") -- here i want to remove all theese \"'s and \' 's
response:gsub('[\"]', '"') -- and i figured out that i cannot put in \ and a "... How can i solve that,too?
print(response)
x = fs.open("___RESPONSE___", "w")
x.write(response)
x.close()




Thanks in advance

Edited by Mikk809h, 04 April 2014 - 11:34 AM.


#2 apemanzilla

  • Members
  • 1,421 posts

Posted 02 April 2014 - 03:52 PM

You don't need the textutils.urlEncode unless you use a GET request. And I wouldn't recommend using a GET request for something like this, so just stick with POST for now :P/>

So basically, use POST only, and remove the textutils.urlEncode

Edited by Apemanzilla, 02 April 2014 - 03:54 PM.


#3 Goof

  • Members
  • 751 posts

Posted 02 April 2014 - 04:34 PM

Ohhh Okay, I will do that, and it works as it should, but....

from my website hosting provider, the following html code is generated after all responses:
<!-- Hosting24 Analytics Code -->
<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->

I tried with
local response=respons.readAll():gsub('allthatshittytext','') -- but this doesnt work...

Do you know a way to delete that code?

Thanks

#4 Wojbie

  • Members
  • 631 posts
  • LocationKinda lost

Posted 02 April 2014 - 05:06 PM

View PostMikk809h, on 02 April 2014 - 04:34 PM, said:

Ohhh Okay, I will do that, and it works as it should, but....

from my website hosting provider, the following html code is generated after all responses:
<!-- Hosting24 Analytics Code -->
<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->

I tried with
local response=respons.readAll():gsub('allthatshittytext','') -- but this doesnt work...

Do you know a way to delete that code?

Thanks

Untested but try using this (i copied it from large project i am working on) :
local response=respons.readAll():gsub(string.gsub([[<!-- Hosting24 Analytics Code -->
<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->]],"[%^%$%(%)%%%.%[%]%*%+%-%?]",function(A) return "%"..A end),'')


Theoretically it should escape all magic characters from that text and make it a proper pattern, theoretically - works in my code but you never know.

Ofcourse thats a bit overkill but simple way escapes me - like always.

Edited by wojbie, 02 April 2014 - 05:10 PM.


#5 Goof

  • Members
  • 751 posts

Posted 02 April 2014 - 05:11 PM

doesnt work ;/

it doesnt delete that text ;(

#6 apemanzilla

  • Members
  • 1,421 posts

Posted 02 April 2014 - 05:49 PM

Use readLine and skip the first three. It doesn't look like that's something that should change often.

local line, data, i = "", "",0
while line do
  i = i + 1
  if i > 3 then
    data = data..file.readLine().."\n"
  else
    file.readLine()
  end
end

Edited by Apemanzilla, 02 April 2014 - 05:53 PM.


#7 Goof

  • Members
  • 751 posts

Posted 02 April 2014 - 06:44 PM

ehhh what? What are you wanting to do there?

I already know the file-handling, but i dont know how to delete this:

<!-- Hosting24 Analytics Code -->
<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->


#8 apemanzilla

  • Members
  • 1,421 posts

Posted 02 April 2014 - 07:10 PM

The code above omits the first three lines which should get rid of that - assuming its at the top of the file.

#9 Goof

  • Members
  • 751 posts

Posted 02 April 2014 - 07:21 PM

Well its actually the opposite.. If you know. Hosting providers often post their links and all that stuffz at the bottom of the html_script, so i cant actually use your code...

But i figured an alternate way to delete it:

local response=respons.readAll():gsub('<!--(.+)','')


#10 Wojbie

  • Members
  • 631 posts
  • LocationKinda lost

Posted 02 April 2014 - 07:26 PM

Facepalm. I knew i was over thinking it. :P

#11 Goof

  • Members
  • 751 posts

Posted 02 April 2014 - 07:53 PM

Btw... If i want to make a fileWriter function, which makes a file, but if the filename already exists it has to make it make a new file, but with the extension "(1)" and "(2)" etc.


how am i able to do that?

something like this?
if string.find(fileName, "([%n])") then
        fileName = fileName:gsub("([(.+)])", "")
      else
        fileName = fileName.."("..currentValue..")"
      end


-- full function code:
Spoiler

thanks in Advance

#12 CometWolf

  • Members
  • 1,283 posts

Posted 02 April 2014 - 08:09 PM

That would probably work, however i could be simplified a bit :P
local function saveFile(path)
  local orgLength = #path
  local curValue = 0
  while fs.exists(path) do
    curValue = curValue+1
    path = path:sub(1,orgLength).."("..curValue..")"
  end
  --savefile here
end


#13 Goof

  • Members
  • 751 posts

Posted 02 April 2014 - 08:53 PM

Uhhhhhh Thank you very much :D
you're right... it is simplified quite a bit xD

Thanks

#14 Goof

  • Members
  • 751 posts

Posted 03 April 2014 - 10:50 PM

The weird return problem has been encountered again...

When getting an uploaded file, all the quotes are having that "\" infront...

I dont use any textutils.urlEncode when posting anything, so im quite lost about how to solve this... :(

Spoiler

Php code can be shown from the website, if wished...

Thanks in advance

#15 apemanzilla

  • Members
  • 1,421 posts

Posted 04 April 2014 - 12:37 PM

View PostMikk809h, on 03 April 2014 - 10:50 PM, said:

The weird return problem has been encountered again...

When getting an uploaded file, all the quotes are having that "\" infront...

I dont use any textutils.urlEncode when posting anything, so im quite lost about how to solve this... :(/>

Spoiler

Php code can be shown from the website, if wished...

Thanks in advance
At this point, it is likely the PHP adding escapes to special characters.

#16 Goof

  • Members
  • 751 posts

Posted 04 April 2014 - 12:45 PM

Is there a way i can fix that, because on Pastbin such things doesn't occour...

php code:
-- removed authcode
Spoiler
pastebin?

Thanks :D

Edited by Mikk809h, 04 April 2014 - 12:46 PM.






3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users