CORONA SDK require "enable Javascript in your browser" while my browser enabled Javascript

I was trying to upload a text file to my internet webpage. It seems okay at the beginning, and then an error appeared, I just know the last sentence said I need to enable Javascript in my browser, but I already enabled it in safari.

6**  09 01:33:47.656 U**pload started

6**  09 01:33:47.665 U**ploading… bytes transferred 17

6**  09 01:33:48.207 U**pload ended…

6**  09 01:33:48.208 S**tatus: 200

6**  09 01:33:48.221 R**esponse: <html><body><script type=“text/javascript” src="/aes.js" ></script><script>function toNumbers(d){var e=[];d.replace(/(…)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f<d.length;f++)e+=(16>d[f]?“0”:"")+d[f].toString(16);return e.toLowerCase()}var a=toNumbers(“f655ba9d09a112d4968c63579db590b4”),b=toNumbers(“98344c2eee86c3994890592585b49f80”),c=toNumbers(“32ecbcd2fe020d39cfa94513997bed23”);document.cookie="__test="+toHex(slowAES.decrypt(c,2,a, B))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/"; document.cookie=“referrer=”+escape(document.referrer); location.href=“http://today.er-webs.com/upload.php?ckattempt=1”;</script><noscript>This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support</noscript></body></html>

You will have to work with the host where the page is stored and have them not check to make sure your a web browser. You PHP script shouldn’t need JavaScript to work. This is usually from sites where people are visiting with a web browser and too much of their display depends on JavaScript so they inject that into the output. They should not be doing that for PHP scripts.

Rob

The code of the upload.php is just like below, no JavaScript, any ideas? thanks a lot :ph34r: :

\<?php $target\_dir = "uploads/"; $target\_file = $target\_dir . basename($\_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = pathinfo($target\_file,PATHINFO\_EXTENSION); if (file\_exists("documenti/$fileName")) &nbsp;{&nbsp; &nbsp;unlink("documenti/$fileName"); echo "\<font face='Verdana' size='2' \>Last Uploaded File has been removed from uploads folder\<br\>back to uploadform agian and upload your file\<br\>"; echo "\<font face='Verdana' size='2' \>\<BR\>\<BR\>\<BR\>\<a href='upform.php'\>Back to upform\</a\>\<BR\>"; &nbsp;}&nbsp; if ($\_FILES["fileToUpload"]["size"] \> 10000) { &nbsp; &nbsp; echo "Sorry, your file is too large."; &nbsp; &nbsp; $uploadOk = 0; } if ($uploadOk == 0) { &nbsp; &nbsp; echo "Sorry, your file was not uploaded."; } else { &nbsp; &nbsp; if (move\_uploaded\_file($\_FILES["fileToUpload"]["tmp\_name"], $target\_file)) { &nbsp; &nbsp; &nbsp; &nbsp; echo "The file ". basename( $\_FILES["fileToUpload"]["name"]). " has been uploaded."; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; echo "Sorry, there was an error uploading your file."; &nbsp; &nbsp; } } ?\>

Who ever manages that website is injecting the code in all HTTP requests instead of just on .html requests. I don’t know how your server is setup, who manages it, but it needs fixed there. Obviouslly your PHP script isn’t generating this. Corona’s networking calls just asks the server to return the results from the URL called. That leaves the server itself as the guilty party.

Rob

I have changed hosting and sub domain, finally no that java script error appear, however, still cannot upload the data to the php.

I saw many people online have same problem also, and they cannot fix it at the end.

Luckily, Network.download GET is still workable.

I think I will make a webpage with form on it and display it in the app for uploading text data.

Have you read this tutorial:  https://coronalabs.com/blog/2014/02/25/tutorial-uploading-files-demystified/

Rob

Hi Rob, I have read the whole page once more time, still have no idea.

Did set the uploads file to be able to be executed and written.

still got the error message below.

6**  21 11:52:20.120 U**pload started

6**  21 11:52:20.490 U**ploading… bytes transferred 49

6**  21 11:52:20.790 U**pload ended…

6**  21 11:52:20.791 S**tatus: 200

6**  21 11:52:20.791 R**esponse: Sorry, there was an error uploading your file.

Can you post your current upload code?

Your current PHP script?

How big is the file you’re trying to upload?

Do you have access to your server’s logs?

Is the file actually on the server by any chance?

The upload script:

local widget = require("widget") local composer = require("composer") local scene = composer.newScene() local json = require( "json" ) local loadsave = require( "loadsave" ) math.randomseed(os.time()) --\*\*\*\*\*\*\*\*\* \*\*\*\*\*\*\*\*\*\*\*-- local myQuestBox local myAnsBoxA local myAnsBoxB local myAnsBoxB local myAnsBoxD local randomNumber = math.random(3) local randomNumber2 = 0 if randomNumber == 3 then randomNumber2 = 1 end local AnsA local AnsB local AnsC local AnsD local QTxt local ref local submitB local returnB local correctAns local AB local BB local CB local DB local AnsChose = false local AnsIs local AW local BW local CW local DW local AnsSelected = false local theAns --\*\*\*\*\*\*\*\*\*\* \*\*\*\*\*\*\*\*\*\*\*-- local ABPressed = function(event) if ("began" == event.phase) then AnsChose = true AnsIs = "A" AW:setFillColor(0,0,1) BW:setFillColor(random2) CW:setFillColor(random2) DW:setFillColor(random3) AnsSelected = true theAns = "A" end end local BBPressed = function(event) if ("began" == event.phase) then AnsChose = true AnsIs = "B" BW:setFillColor(0,0,1) AW:setFillColor(random2) CW:setFillColor(random2) DW:setFillColor(random2) AnsSelected = true theAns = "B" end end local CBPressed = function(event) if ("began" == event.phase) then AnsChose = true AnsIs = "C" CW:setFillColor(0,0,1) AW:setFillColor(random2) BW:setFillColor(random2) DW:setFillColor(random2) AnsSelected = true theAns = "C" end end local DBPressed = function(event) if ("began" == event.phase) then AnsChose = true AnsIs = "D" DW:setFillColor(0,0,1) AW:setFillColor(random2) BW:setFillColor(random2) CW:setFillColor(random2) AnsSelected = true theAns = "D" end end local function networkListener( event ) if ( event.isError ) then print( "Network Error." ) else if ( event.phase == "began" ) then print( "Upload started" ) elseif ( event.phase == "progress" ) then print( "Uploading... bytes transferred ", event.bytesTransferred ) elseif ( event.phase == "ended" ) then print( "Upload ended..." ) print( "Status:", event.status ) print( "Response:", event.response ) end end end local toUpload = function () network.upload( "http://mcno.orgfree.com/upload.php", "POST", networkListener, "myTable.json", system.DocumentsDirectory, "application/json" ) end local submitBPressed = function(event) if ("began" == event.phase) then if AnsA.edited == true and AnsB.edited == true and AnsC.edited == true and AnsD.edited == true and QTxt.edited == true and AnsSelected == true then local t ={theAns,AnsA.text, AnsB.text, AnsC.text, AnsD.text, QTxt.text, ref.text} loadsave.saveTable(t, "myTable.json", system.DocumentsDirectory) loadsave.printTable(t) toUpload() composer.gotoScene( "uploaded" ) else print("Not ok") end end end local returnBPressed = function(event) if ("began" == event.phase) then composer.gotoScene( "start" ) end end local function textListener( event ) if ( event.phase == "began" ) then event.target.text="" -- User begins editing "defaultField" elseif ( event.phase == "ended" or event.phase == "submitted" ) then -- Output resulting text from "defaultField" print( event.target.text ) elseif ( event.phase == "editing" ) then if event.startPosition \> 0 then event.target.edited = true end --print( event.text ) end end --\*\*\*\*\*\*\*\*\*\*\*\* Composer \*\*\*\*\*\*\*\*\*\*\*\*\*-- function scene:create(event) local screenGroup = self.view myQuestBox = display.newImageRect( "dialog"..randomNumber..".png",display.contentWidth,display.contentHeight/2 ) myQuestBox.x = display.contentWidth/2 myQuestBox.y = display.contentHeight/4 screenGroup:insert(myQuestBox) local AButton = display.newImageRect( "button-on"..randomNumber..".png", display.contentWidth/2, display.contentHeight/4 ) AButton.x = display.contentWidth/4 AButton.y = display.contentHeight/8\*5 screenGroup:insert(AButton) local BButton = display.newImageRect( "button-on"..randomNumber..".png", display.contentWidth/2, display.contentHeight/4 ) BButton.x = display.contentWidth\*3/4 BButton.y = display.contentHeight/8\*5 screenGroup:insert(BButton) local CButton = display.newImageRect( "button-on"..randomNumber..".png", display.contentWidth/2, display.contentHeight/4 ) CButton.x = display.contentWidth/4 CButton.y = display.contentHeight/8\*7 screenGroup:insert(CButton) local DButton = display.newImageRect( "button-on"..randomNumber..".png", display.contentWidth/2, display.contentHeight/4 ) DButton.x = display.contentWidth\*3/4 DButton.y = display.contentHeight/8\*7 screenGroup:insert(DButton) AnsA = native.newTextField(display.contentWidth/4, display.contentHeight/8\*5,display.contentWidth/2,display.contentHeight/6) AnsA:setTextColor( randomNumber2 ) AnsA.hasBackground = false AnsA.font = native.newFont( native.systemFontBold, 54 ) AnsA.align = "center" AnsA.isEditable = true AnsA.text="AnsA" AnsA.edited=false screenGroup:insert(AnsA) AnsB = native.newTextField(display.contentWidth\*3/4, display.contentHeight/8\*5,display.contentWidth/2,display.contentHeight/6) AnsB:setTextColor( randomNumber2 ) AnsB.hasBackground = false AnsB.font = native.newFont( native.systemFontBold, 54 ) AnsB.align = "center" AnsB.isEditable = true AnsB.text="AnsB" AnsB.edited=false screenGroup:insert(AnsB) AnsC = native.newTextField(display.contentWidth/4, display.contentHeight/8\*7,display.contentWidth/2,display.contentHeight/6) AnsC:setTextColor( randomNumber2 ) AnsC.hasBackground = false AnsC.font = native.newFont( native.systemFontBold, 54 ) AnsC.align = "center" AnsC.isEditable = true AnsC.text="AnsC" AnsC.edieted =false screenGroup:insert(AnsC) AnsD = native.newTextField(display.contentWidth\*3/4, display.contentHeight/8\*7,display.contentWidth/2,display.contentHeight/6) AnsD:setTextColor( randomNumber2 ) AnsD.hasBackground = false AnsD.font = native.newFont( native.systemFontBold, 54 ) AnsD.align = "center" AnsD.isEditable = true AnsD.text="AnsD" AnsD.edited=false screenGroup:insert(AnsD) QTxt = native.newTextField(display.contentWidth/2, display.contentHeight/4,display.contentWidth-40,display.contentHeight/5) QTxt:setTextColor( randomNumber2 ) QTxt.hasBackground = false QTxt.font = native.newFont( native.systemFontBold, 54 ) QTxt.align = "center" QTxt.isEditable = true QTxt.text="Question Here\nselect answer above" QTxt.edited=false QTxt:setReturnKey( "done" ) screenGroup:insert(QTxt) ref = native.newTextField(display.contentWidth/2, display.contentHeight/2-170,display.contentWidth-40,display.contentHeight/11) ref:setTextColor( randomNumber2 ) ref.hasBackground = false ref.font = native.newFont( native.systemFontBold, 30 ) ref.align = "center" ref.isEditable = true ref.text="Hints/explanation Here" ref.edited=false screenGroup:insert(ref) submitB = widget.newButton{ width = display.contentWidth/3, height = display.contentWidth/6 , defaultFile = "button-on"..randomNumber..".png", overFile = "button-off"..randomNumber..".png", onEvent = submitBPressed, } submitB.x = display.contentWidth - display.contentWidth/6 submitB.y = display.contentWidth/12 screenGroup:insert(submitB) local submitWOpt= { text = "Submit", x = display.contentWidth - display.contentWidth/6, y = display.contentWidth/12, fontSize = 54, width = display.contentWidth/2-40, height = 0, font = native.systemFontBold, align = "center" } submitW = display.newText(submitWOpt) submitW:setFillColor( randomNumber2 ) screenGroup:insert(submitW) returnB = widget.newButton{ width = display.contentWidth/3, height = display.contentWidth/6 , defaultFile = "button-on"..randomNumber..".png", overFile = "button-off"..randomNumber..".png", onEvent = returnBPressed, } returnB.x = display.contentWidth - display.contentWidth/6 returnB.y = 510 screenGroup:insert(returnB) local returnWOpt= { text = "Return", x = display.contentWidth - display.contentWidth/6, y = 510, fontSize = 54, width = display.contentWidth/2-40, height = 0, font = native.systemFontBold, align = "center" } returnW = display.newText(returnWOpt) returnW:setFillColor( randomNumber2 ) screenGroup:insert(returnW) AB = widget.newButton{ width = display.contentWidth/6, height = display.contentWidth/6 , defaultFile = "button-on"..randomNumber..".png", overFile = "button-off"..randomNumber..".png", onEvent = ABPressed, } AB.x = display.contentWidth/12 AB.y = display.contentWidth/12 screenGroup:insert(AB) BB = widget.newButton{ width = display.contentWidth/6, height = display.contentWidth/6 , defaultFile = "button-on"..randomNumber..".png", overFile = "button-off"..randomNumber..".png", onEvent = BBPressed, } BB.x = display.contentWidth/12+display.contentWidth/6 BB.y = display.contentWidth/12 screenGroup:insert(BB) CB = widget.newButton{ width = display.contentWidth/6, height = display.contentWidth/6 , defaultFile = "button-on"..randomNumber..".png", overFile = "button-off"..randomNumber..".png", onEvent = CBPressed, } CB.x = display.contentWidth/12+display.contentWidth/3 CB.y = display.contentWidth/12 screenGroup:insert(CB) DB = widget.newButton{ width = display.contentWidth/6, height = display.contentWidth/6 , defaultFile = "button-on"..randomNumber..".png", overFile = "button-off"..randomNumber..".png", onEvent = DBPressed, } DB.x = display.contentWidth/12+display.contentWidth/2 DB.y = display.contentWidth/12 screenGroup:insert(DB) local AWOpt= { text = "A",--G [3][1].b, --33 digits maximize x = display.contentWidth/12, y = display.contentWidth/12, fontSize = 54, width = display.contentWidth/2-40, height = 0, font = native.systemFontBold, align = "center" } AW = display.newText(AWOpt) AW:setFillColor( randomNumber2 ) screenGroup:insert(AW) local BWOpt= { text = "B",--G [3][1].b, --33 digits maximize x = display.contentWidth/12+display.contentWidth/6, y = display.contentWidth/12, fontSize = 54, width = display.contentWidth/2-40, height = 0, font = native.systemFontBold, align = "center" } BW = display.newText(BWOpt) BW:setFillColor( randomNumber2 ) screenGroup:insert(BW) local CWOpt= { text = "C",--G [3][1].b, --33 digits maximize x = display.contentWidth/12+display.contentWidth/3, y = display.contentWidth/12, fontSize = 54, width = display.contentWidth/2-40, height = 0, font = native.systemFontBold, align = "center" } CW = display.newText(CWOpt) CW:setFillColor( randomNumber2 ) screenGroup:insert(CW) local DWOpt= { text = "D",--G [3][1].b, --33 digits maximize x = display.contentWidth/12+display.contentWidth/2, y = display.contentWidth/12, fontSize = 54, width = display.contentWidth/2-40, height = 0, font = native.systemFontBold, align = "center" } DW = display.newText(DWOpt) DW:setFillColor( randomNumber2 ) screenGroup:insert(DW) end function scene:show(event) if event.phase =="did" then composer.removeScene("menu") AnsA:addEventListener( "userInput", textListener ) AnsB:addEventListener( "userInput", textListener ) AnsC:addEventListener( "userInput", textListener ) AnsD:addEventListener( "userInput", textListener ) QTxt:addEventListener( "userInput", textListener ) ref:addEventListener( "userInput", textListener ) end end function scene:hide( event ) if event.phase =="will" then AnsA:removeSelf() AnsA = nil AnsB:removeSelf() AnsB = nil AnsC:removeSelf() AnsC = nil AnsD:removeSelf() AnsD = nil QTxt:removeSelf() QTxt = nil ref:removeSelf() ref = nil end end function scene:destroy( event ) if event.phase =="will" then end end scene:addEventListener("create", scene) scene:addEventListener("show", scene) scene:addEventListener("hide", scene) scene:addEventListener("destroy", scene) return scene

php:

\<?php $target\_dir = "uploads/"; $target\_file = $target\_dir . basename($\_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = pathinfo($target\_file,PATHINFO\_EXTENSION); if ($\_FILES["fileToUpload"]["size"] \> 500000) { echo "Sorry, your file is too large."; $uploadOk = 0; } if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; } else { if (move\_uploaded\_file($\_FILES["fileToUpload"]["tmp\_name"], $target\_file)) { echo "The file ". basename( $\_FILES["fileToUpload"]["name"]). " has been uploaded."; } else { echo "Sorry, there was an error uploading your file."; } } ?\>

the log:

7 08 12:47:50.662 Upload ended…

                    Status: 200

                    Response: Sorry, there was an error uploading your file.

The upload file is just a text typed by user, should be very small, so can be able to upload. And the upload file set chmod value to 777, to be able to write, However, checked in the serve no myTable.json in “uploads” file.

still have no clue why cannot be uploaded.

move\_uploaded\_file($\_FILES["fileToUpload"]["tmp\_name"], $target\_file)

is returning false. The Status: 200 means the webserver believes it completed the script correctly. You’re getting the echo statement that you should if that condition is false.

I would print out $target_file, print out $_FILES[“fileToUpload”][“tmp_name”]. Make sure uploads is a child folder of where the script runs (even though that may not be the most safe thing to do) or change the uploads folder somewhere that’s not a child of your script folder.

Rob

not sure your meaning…as I just start using PHP. I changed the PHP

 if (move\_uploaded\_file($\_FILES["fileToUpload"]["tmp\_name"], $target\_file)) { echo "The file ". basename( $\_FILES["fileToUpload"]["name"]). " has been uploaded."; } else { echo "Sorry, there was an error uploading your file."; echo "target file"; echo $target\_file; echo "temp name"; echo $\_FILES["fileToUpload"]["tmp\_name"]; } }

and the log become:

7 08 04:54:36.331 Upload ended…

7 08 04:54:36.331 Status: 200

                    Response: Sorry, there was an error uploading your file.target fileuploads/temp name

I am thinking is it because fileToUpload is wrong. File name should not be $_FILES[“fileToUpload”][“tmp_name”], how can I know the file name? thanks.

You can do a:

print_r( $_FILES );

and see what’s actually in the $_FILES table

got empty array, try to figure it out now :ph34r:  :

Array

                    (

                    )

Instead of using “POST” to upload the file, try “PUT” and see if that changes anything.

Rob

the result is the same:

7 10 12:19:17.416 Status: 200

                    Response: Array

                    (

                    )

                    Sorry, there was an error uploading your file.

Did you look at our sample upload script?

https://www.dropbox.com/s/yc3z9a9xgf5kkim/upload.php

Rob

Dearest Rob, you are awesome! I finally can upload by the upload.php you provided! I wish I could see it earlier.

For other people reference, I changed the lua code also, as the previous one said it is Malformed Request, the updated code is as below:

local toUpload = function () local url = "http://mcno.orgfree.com/upload.php" local params = { timeout = 60 } local filename = "myQuest.json" local t ={theAns,AnsA.text, AnsB.text, AnsC.text, AnsD.text, QTxt.text, ref.text} headers = {} headers.filename = filename params.headers = headers params.body = json.encode(t) network.request(url, "POST", networkListener, params ) end

You will have to work with the host where the page is stored and have them not check to make sure your a web browser. You PHP script shouldn’t need JavaScript to work. This is usually from sites where people are visiting with a web browser and too much of their display depends on JavaScript so they inject that into the output. They should not be doing that for PHP scripts.

Rob

The code of the upload.php is just like below, no JavaScript, any ideas? thanks a lot :ph34r: :

\<?php $target\_dir = "uploads/"; $target\_file = $target\_dir . basename($\_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = pathinfo($target\_file,PATHINFO\_EXTENSION); if (file\_exists("documenti/$fileName")) &nbsp;{&nbsp; &nbsp;unlink("documenti/$fileName"); echo "\<font face='Verdana' size='2' \>Last Uploaded File has been removed from uploads folder\<br\>back to uploadform agian and upload your file\<br\>"; echo "\<font face='Verdana' size='2' \>\<BR\>\<BR\>\<BR\>\<a href='upform.php'\>Back to upform\</a\>\<BR\>"; &nbsp;}&nbsp; if ($\_FILES["fileToUpload"]["size"] \> 10000) { &nbsp; &nbsp; echo "Sorry, your file is too large."; &nbsp; &nbsp; $uploadOk = 0; } if ($uploadOk == 0) { &nbsp; &nbsp; echo "Sorry, your file was not uploaded."; } else { &nbsp; &nbsp; if (move\_uploaded\_file($\_FILES["fileToUpload"]["tmp\_name"], $target\_file)) { &nbsp; &nbsp; &nbsp; &nbsp; echo "The file ". basename( $\_FILES["fileToUpload"]["name"]). " has been uploaded."; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; echo "Sorry, there was an error uploading your file."; &nbsp; &nbsp; } } ?\>

Who ever manages that website is injecting the code in all HTTP requests instead of just on .html requests. I don’t know how your server is setup, who manages it, but it needs fixed there. Obviouslly your PHP script isn’t generating this. Corona’s networking calls just asks the server to return the results from the URL called. That leaves the server itself as the guilty party.

Rob