Source language: Translate to:

Upload image using php with POST

Questions and information about creating Internet aware NeoBook applications. Including PHP, HTML, FTP, HTTP, Email, etc.

Moderator: Neosoft Support

Upload image using php with POST

Postby josesito » Tue Jul 22, 2014 12:28 am

Perhaps someone can give me a little help with this:
I need to upload image files using php. The traditional way to do it is with a html form, submitting the file to a php script and then the file selected is uploaded. If I use this method everything works fine. With neobook I have been able to submit data to databases using this procedure, but I haven´t been able to complete the task when files are involved. I know the problem is with the name of the file submitted from neobook, I tried everything without luck. I include here the files for you to test it. Thank you in advance for your help.

This is the php---------------------------- upload.php
Code: Select all
<?php
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);

      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
?>


This is the html (if you need it for testing in your server)
Code: Select all
<html>
<body>

<form action="upload.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>

</body>
</html>



This is the pub:
Code: Select all
NBW Publication Source File
(C)2014 NeoSoft Corp.
Title=Untitled NeoBook Publication
Language=US
NeoBookVer=5.80
ScreenColors=16777216
ScreenWidth=640
ScreenHeight=480
BkndColor=0
ScreenAutoSize=Yes
LinkColor=16711680
WindowStyle=0
WindowOrder=0
WindowPos=0
WindowProps=31
BiDiMode=0
UseUpdateTimer=Yes
ReturnTime=60
ShapeTransColor=536870912
SplashProps=3
CompileType=0
MediaType=0
FilesIncluded=1
FontsIncluded=2
CopyExternalFiles=No
SetupMedia=3
SetupInstDir=C:\MyProgram
SetupTitle=Setup
SetupColors=16711680|0|65535
Variables=[archivo]¶[resultado]¶
VersionMajor=1
VersionMinor=0
VersionRelease=0
VersionBuild=0
ReqExLevel=1
CustomFontName=Arial
CustomFontSize=9
CustomFontStyle=0
CustomCharset=1
CacheSize=30
ExtractOp=132
L_OK=OK
L_CANCEL=Cancel
L_YES=Yes
L_NO=No
L_CLOSE=Close
L_ERRORTITLE=Error
L_FINDTITLE=Find
L_FINDPROMPT=Find &What
L_FINDFIRST=&Find First
L_FINDNEXT=Find &Next
L_FINDERROR=Search text not found.
L_PWORDTITLE=Password required
L_PWORDMSG=Before continuing, you must first|enter the correct password.
L_PWORDPROMPT=&Password:
L_PWORDERROR=That's not the right password!
L_MEDIAERROR=In order to play this type of file you must install|the appropriate multimedia hardware and/or|software.
L_INTERNETERROR=Unable to locate Internet Browser software.
L_ABORTFUNCTION=Do you want to cancel this function?
L_EXTRACTERROR=This file could not be extracted and cannot be played.
L_INSTDIRPROMPT=Please enter the drive and directory where you would like this program to be installed. To accept the default drive and directory, simply press Enter.
L_INSTFOLDERPROMPT=Do you wish to create a program folder?
L_INSTRUNPROMPT=Do you want to run
L_INSTDISKPROMPT=Please insert disk #
L_INSTDISKERROR=That's not the correct disk, try again.
L_INSTGENERROR=The installation has terminated.
L_INSTEXITPROMPT=Do you really want to cancel the installation?
L_INSTWINTITLE=Setup
L_INSTPROGTITLE=Extracting Files...
L_SENDEMAIL=Sending Mail...
L_MAILSERVER=Please enter the name of your outgoing email server:
L_COPY=Copy to Clipboard
L_SELECTALL=Select All
L_DONWLOADFILE=Downloading: %s
L_PLEASEWAIT=Please wait...
TrayMenuBegin
MenuName=TrayOpen
MenuText=Open
MenuState=3
MenuKey=0
MenuAction=SetVar "[WindowState]" "Normal"
MenuName=TrayExit
MenuText=Exit
MenuState=3
MenuKey=0
MenuAction=Exit "" ""
MenuEnd
MasterPage
NewPage=New Page
PageStyle=0
PageColor=16777215
PageGradient1=16711680
PageGradient2=255
PageGradientDir=1
WallpaperStyle=0
ObjectType=3
Name=PushButton3
X=80
Y=112
W=516
H=197
Anchor=0
Text=Upload file
Align=2
ImageStyle=0
BevelWidth=0
XPTheme=Yes
ObjAction=InternetPost "http://mydomain.com/upload.php" "name=examplefile.txt" "[resultado]" ""
LineColor=0
LineWidth=1
LineStyle=0
FillColor=-16777201
FillPattern=0
Font=Arial
FontSize=12
FontStyle=1
FontCharset=1
TextColor=0
TabOrder=1
josesito
 
Posts: 53
Joined: Sat Sep 26, 2009 6:44 pm

Re: Upload image using php with POST

Postby Gaev » Tue Jul 22, 2014 6:15 am

josesito:

I believe that File Uploads always require User Actions ... otherwise, people with malicious intent could upload important data from your local disk (without your knowledge) merely by enticing you to visit a page on their website.
User avatar
Gaev
 
Posts: 3728
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Upload image using php with POST

Postby Neosoft Support » Tue Jul 22, 2014 10:11 am

Maybe you could place your html form in an off-screen WebBrowser object, fill in the form with NeoBook's BrowserSetElement action, and "click" the submit button with the BrowserExecScript action.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5602
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Re: Upload image using php with POST

Postby josesito » Tue Jul 22, 2014 10:37 am

Thank you Gaev and Dave, I will try your suggestion.
josesito
 
Posts: 53
Joined: Sat Sep 26, 2009 6:44 pm

Re: Upload image using php with POST

Postby virger » Tue Jul 22, 2014 10:51 am

Hi:
Last year it worked out well

PUB (subelo.pub) with this WEB
Code: Select all
{NeoBook 5 Objects}
NeoBookVer=5,80
ObjectType=14
Name=Web
X=0
Y=0
W=310
H=67
Anchor=1
FileName=www.elservidor.com\subelo.html
VarName=[WebStatus]
TitleVarName=[WebTitle]
URLVarName=[WebAddr]
ScrollBar=Yes
LineColor=0
LineWidth=0
LineStyle=0
FillColor=-16777201
FillPattern=0
Font=Arial
FontSize=12
FontStyle=1
FontCharset=1
TextColor=0
TabOrder=2


The HTML (subelo.html)
Code: Select all
<form enctype="multipart/form-data" action="subelo.php" method="post">
    <input name="img" type="file" />
      <input type="submit" name="submit" value="Send">
</form>


And the PHP (subelo.php)
Code: Select all
<?php
move_uploaded_file($_FILES["img"]["tmp_name"],"imagenes/" . $_FILES["img"]["name"]);
echo "<script>window.history.back();</script>";
?>


I hope to help you

We made HISTORY.
We are LEGEND.
From Costa Rica
PURA VIDA
COSTA RICA
PURA VIDA
User avatar
virger
 
Posts: 518
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central

Re: Upload image using php with POST

Postby josesito » Tue Jul 22, 2014 10:56 am

Gracias Viger, saludos desde Guatemala.
josesito
 
Posts: 53
Joined: Sat Sep 26, 2009 6:44 pm

Re: Upload image using php with POST

Postby Ferdari » Sun May 10, 2015 12:26 pm

You can upload all kind of files with this code,in a button:
Code: Select all
FileOpenBox "" "Any File|*.*" "[MyDocuments]" "[File]" ""

hpwMimeEncodeFile "[File]" "[PubDir]\file.encode"

ExtractFileExt "[File]" "[ext]"
ExtractFileName "[File]" "[filename]"
StrParse "[filename]" "." "[filename]" ""

FileRead "[PubDir]\file.encode" "All" "[fileR]"
StrReplace "[fileR]" "[#13]" "" "[fileR]" ""
StrReplace "[fileR]" "[#10]" "" "[fileR]" ""
StrReplace "[fileR]" " " "" "[fileR]" ""

Call "URIencode" "[fileR]" "[fileRSafe]"
InternetPost "http://www.yourserver.com/form.php" "fn=[filename1]&ext=[ext]&f=[fileRSafe]" "[Result]" ""

If "[Result]" "<>" "true"
   AlertBox "Ocurrió un error!" "[Result]"
endif


**You need HPWUtility Plugin**


Then you need to save this to a file called "URIencode" without extension to you Neobook Functions dir:
Code: Select all
{NeoBook Function}
Version=5.80
Language=JScript
Param=[%Text]|Mixed|Data to encode (Mixed, text & numbers)
Param=[Output]|Variable|Result variable
{End}
var text2encode;
text2encode = encodeURIComponent('[%Text]');
nbSetVar('[Output]', text2encode);


Next you need to upload an PHP file named "form.php" to your server:
Code: Select all
<?php

$ext = $_POST['ext'];//Extension
$file = $_POST['f'];//The file contents in Binary Base64
$fn = $_POST['fn'];//Filename
$filePath = "files/".$fn.$ext;

if(file_put_contents($filePath,base64_decode($file))){
    echo "true";
}else{
    echo "false";
}

?>


Now in your server where you placed your "form.php" file you need to create a folder called "files" with permissions "777" this means all permissions granted for everyone(READ WRITE EXECUTE).

That's all! Have fun! :D
WARNING: Do not abuse of this!, use at your own risk

Also: Don't let people tell you it's impossible, there is always a way.
http://www.noten.in
We have Apps!
Ferdari
 
Posts: 32
Joined: Sun Sep 13, 2009 9:34 pm

Re: Upload image using php with POST

Postby josesito » Sun May 10, 2015 4:54 pm

Thank you, I guess this will be very useful for the whole community.
josesito
 
Posts: 53
Joined: Sat Sep 26, 2009 6:44 pm


Return to NeoBook and the Internet

Who is online

Users browsing this forum: No registered users and 0 guests