WAP up/down script
Har download et upload/download-script fra:http://gmtt.co.uk/files.php?cat=12
Har sat det op her: http://www.chatzone.dk/
Man kan fint uploade et billede.
Når billedet er uploadet skriver den man skal gå ind på chatzone.dk og taste et ID for at hente billedet.
Problemet er bare når man går ind på chatzone.dk via mobilen, kommer man til uploadsiden, og ikke en downloadside.
Tvivler på min server er sat korrekt op til WAP.
Filerne som benyttes er:
__________________________________________________________________
config.php (database er sat rigtigt op) >
<?php
//EDIT THE VARIABLES BELOW
$dbserver = "localhost"; // DATABASE HOST
$username = ""; // DATABASE USERNAME
$password = ""; // DATABASE PASsWORD
$database = ""; // DATABASE NAME
$urltoindex = "http://chatzone.dk"; //path where the script files reside in remember NO trailing slash
$hostpage = "http://chatzone.dk/tmpfiles/"; // directory on server where files are saved remember trailing slash
$allowedsize = 512000; //allowed upload file size in bytes
// END EDITABLE REGION
/////DO NOT EDIT BELOW
$db = mysql_connect($dbserver, $username, $password);
mysql_select_db($database,$db);
?>
__________________________________________________________________
download.php >
<?php
// send wml headers
header("Content-type: text/vnd.wap.wml"); // set the correct MIME type
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // expires in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Last modified, right now
header("Cache-Control: no-cache, must-revalidate"); // Prevent caching, HTTP/1.1
header("Pragma: no-cache"); // Prevent caching, HTTP/1.0
echo("<?xml version=\"1.0\"?>");
?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<!-- begin new deck -->
<wml>
<!-- begin card -->
<card title="Downloader" newcontext="true">
<p>
<?php
include 'config.php';
$idnm = $_POST['idnm'];
$sql = ("SELECT * FROM wapupld_upload WHERE idnm='$idnm'");
$result = mysql_query($sql, $db);
$rs = mysql_fetch_array($result);
if($rs){
$filname = $rs['filname'];
$downloadurl = $hostpage . $filname;
echo("File found: $filname");
echo("<br/>ID: $idnm");
echo("<anchor title='download'>");
echo("<br/>click here to download");
echo("<go href='$downloadurl' method='get'>");
echo("</go>");
echo("</anchor>");
}
else {
echo("No files found");
}
echo("<br/><br/><anchor title='back'>");
echo("click here to go back");
echo("<go href='$urltoindex' method='get'>");
echo("</go>");
echo("</anchor>");
?>
</p>
</card>
</wml>
__________________________________________________________________
index.php >
<?
include 'config.php';
if(strpos(strtoupper($HTTP_ACCEPT),"VND.WAP.WML") > 0) { // Check whether the browser/gateway says it accepts WML.
$br = "WML";
}
else {
$browser=substr(trim($HTTP_USER_AGENT),0,4);
if($browser=="Noki" || // Nokia phones and emulators
$browser=="Eric" || // Ericsson WAP phones and emulators
$browser=="WapI" || // Ericsson WapIDE 2.0
$browser=="MC21" || // Ericsson MC218
$browser=="AUR " || // Ericsson R320
$browser=="R380" || // Ericsson R380
$browser=="UP.B" || // UP.Browser
$browser=="WinW" || // WinWAP browser
$browser=="UPG1" || // UP.SDK 4.0
$browser=="upsi" || // another kind of UP.Browser ??
$browser=="QWAP" || // unknown QWAPPER browser
$browser=="Jigs" || // unknown JigSaw browser
$browser=="Java" || // unknown Java based browser
$browser=="Alca" || // unknown Alcatel-BE3 browser (UP based?)
$browser=="MITS" || // unknown Mitsubishi browser
$browser=="MOT-" || // unknown browser (UP based?)
$browser=="My S" || // unknown Ericsson devkit browser ?
$browser=="WAPJ" || // Virtual WAPJAG www.wapjag.de
$browser=="fetc" || // fetchpage.cgi Perl script from www.wapcab.de
$browser=="ALAV" || // yet another unknown UP based browser ?
$browser=="Wapa") // another unknown browser (Web based "Wapalyzer"?)
{
$br = "WML";
}
else {
$br = "HTML";
}
}
if($br == "WML") {
// send wml headers
header("Content-type: text/vnd.wap.wml"); // set the correct MIME type
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // expires in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Last modified, right now
header("Cache-Control: no-cache, must-revalidate"); // Prevent caching, HTTP/1.1
header("Pragma: no-cache"); // Prevent caching, HTTP/1.0
echo("<?xml version=\"1.0\"?>");
?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<!-- begin new deck -->
<wml>
<!-- begin card -->
<card title="wapuploader" newcontext="true">
<?php
include 'config.php';
echo("<p>Download your file<br/><br/></p>");
?>
<p>
Id: <input type="text" name="idnm" format="6N"/>
<br/>
<anchor title="Login">
Find file
<go href="download.php" method="post">
<postfield name="idnm" value="$idnm"/>
</go>
</anchor>
<br/>
</p>
</card>
</wml> <?
}
else {
// IF THE PAGE IS ACCESSED BY HTTP INSTEAD OF WAP
$nu = time();
$sql = ("SELECT * FROM wapupld_upload");
$result = mysql_query($sql, $db);
$enable = 0;
while($rs = mysql_fetch_array($result) ){
$uptime = $rs["dato"];
$idnm = $rs["idnm"];
$filname = $rs["filname"];
}
?>
<div align="center">GMTT - Wap Upload / Download System
</div>
<form enctype='multipart/form-data' action='<?php echo("$urltoindex");?>/uploadfile.php' method='post'>
<div align="center">
<table width="326" border='1' align="center" cellpadding='0' cellspacing='0' bordercolor="#000000">
<tr>
<td width="102"><p align="right">File: </font></td>
<td width="218"><div align="center">
<input name='fil' type='file'>
</div></td>
</tr>
<tr>
<td><p align="right">File size limit: </font></td>
<td><?php $r = $allowedsize/1024; echo("$r kb");?></td>
</tr>
<tr>
<td><div align="center">
<input name='submit' type='submit' value='Send File'>
</div></td>
<td><div align="center"></div></td>
</tr>
<input type='hidden' name='from' value='tree'>
</table>
</div>
</form>
<? } ?>
__________________________________________________________________
uploadfile.php
<?php
include 'config.php';
//Her skal filen flyttes fra
$src = $_FILES['fil']['tmp_name'];
//Hvilken type fil arbejder vi med?
$ext = strtolower(end(explode(".", $_FILES['fil']['name'])));
$filnavn = $_FILES['fil']['name'];
$tid = substr(time(), 4);
$nytNavn = $tid.".".$ext;
if(substr($tid,5)== 0)
autom($urltoindex,$urltoindex);
$dst = "tmpfiles/" . $nytNavn;
copy($src, $dst);
$fsize = filesize($dst);
if(($fsize >= $allowedsize) OR $ext=="php" OR $ext=="htm" OR $ext=="html") {
unlink("tmpfiles/$nytNavn");
echo("file not uploaded");
}
else { //upload
$min = $timeallowed/60;
$hours = $min/60;
echo("File uploaded, go to $urltoindex and enter this id: $tid<br>");
//gem i db
$sql = ("INSERT INTO wapupld_upload(idnm,filname,dato) VALUES('$tid','$nytNavn','".time()."')");
mysql_query($sql, $db);
}
echo("<br><a href='$urltoindex/index.php'>Click here to upload a new file</a>");
?>