Click here to Skip to main content
15,887,822 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
GeneralRe: I want to clear something about PHP and HTML (newbie) Pin
Jon Heather25-Jan-12 9:40
Jon Heather25-Jan-12 9:40 
AnswerRe: I want to clear something about PHP and HTML (newbie) Pin
markkuk24-Jan-12 0:52
markkuk24-Jan-12 0:52 
GeneralRe: I want to clear something about PHP and HTML (newbie) Pin
flashery24-Jan-12 1:11
flashery24-Jan-12 1:11 
AnswerRe: I want to clear something about PHP and HTML (newbie) Pin
Necron81-Feb-12 5:18
Necron81-Feb-12 5:18 
Question2 outta 3 ain't bad....but why is ftp_put() failing...? Pin
cjoki23-Jan-12 10:30
cjoki23-Jan-12 10:30 
AnswerRe: 2 outta 3 ain't bad....but why is ftp_put() failing...? Pin
User 171649223-Jan-12 11:50
professionalUser 171649223-Jan-12 11:50 
GeneralRe: 2 outta 3 ain't bad....but why is ftp_put() failing...? Pin
cjoki27-Jan-12 4:51
cjoki27-Jan-12 4:51 
QuestionA form data with cascading dropdown and photo for upload Pin
awedaonline23-Jan-12 4:03
awedaonline23-Jan-12 4:03 
Hi all;

I am create a page with data form with phot upload capability and I don't seem to be getting it right. Below is what I have done so far but not working.

index.php

PHP
<pre><?php 
    include_once 'includes/helpers.inc.php';
    require_once 'classes/CommonData.php';
?>
<?php
    if (isset ($_GET['upload'])){
        if (isset($_GET['destination']) && isset ($_GET['allowedFiles'])) {
            $allowedFiles = explode(',', $_GET['allowedFiles']);
        
            if (sizeof($allowedFiles) == 0)
            $allowedFiles = $_GET['allowedFiles'];
        
            if (in_array($_FILES["file"]["type"], $allowedFiles)) {
                if ($_FILES['file']['error'] > 0) {
                    $src = '';
                    $imgMsg = "Return code: " . $_FILES['file']['error'];
                } else {
                    if ($_FILES['file']['size'] > $_GET['maximumFileSize']) {
                        $src = '';
                        $imgMsg = 'File size to large. Must be less or equals 10KB.';
                    } else {
                        if (file_exists($_GET['destination'] . $_FILES['file']['name'])) {
                            $src = '';
                            $imgMsg = $_FILES['file']['name'] . ' already exists.';
                        } else {
                            move_uploaded_file($_FILES['file']['tmp_name'] , 
                                    $_GET['destination'] . $_FILES['file']['name']);
                            $src = $_GET['destination'] . $_FILES['file']['name'];
                            $imgMsg = '';
                            echo $src;
                        }
                    }
                }
            } else {
                $src = '';
                $imgMsg = 'Invalid file type.';
            }
        } else {
            $src = '';
            $imgMsg = 'File destination not specified.';
        }
        
        $surname = ''; //'html($_POST['surname']);
        $otherNames = ''; //html($_POST['otherNames']);
        $contactAddress = ''; //html($_POST['contactAddress']);
        $email = ''; //html($_POST['email']);
        $phone = ''; //html($_POST['phone']);
        $occupation = ''; //html($_POST['occupation']);
        $officeAddress = ''; //html($_POST['officeAddress']);        
        
        include 'views/registration.php';
    } elseif (isset ($_GET['registration'])) {
        $src = '';
        $imgMsg = '';
        $surname = '';
        $otherNames = '';
        $contactAddress = '';
        $email = '';
        $phone = '';
        $occupation = '';
        $officeAddress = '';
        
        include 'views/registration.php';
    } else {
        include 'views/home.php';
    }

?>



registration.php

PHP
<pre><!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><?php setPageTitle('Home'); ?></title>
        <link href="styles/site.css" rel="stylesheet" type="text/css"/>
        <script type="text/javascript" src="scripts/jquery-1.6.2.js"></script>
        <script type="text/javascript" src="scripts/utility.js"></script>
        <script type="text/javascript">
            function getState(countryId) {				
		var strURL="shared/finder/_find-states-by-country-id.php?country="+countryId;
		var req = getXMLHTTP();
		if (req) {
                    req.onreadystatechange = function() {
                        if (req.readyState == 4) {
                            // only if "OK"
                            if (req.status == 200) {						
                                document.getElementById('statediv').innerHTML = req.responseText;						
                            } else {
                                alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                            }
                        }				
                    }			
                    req.open("GET", strURL, true);
                    req.send(null);
		}		
            }
            $(function() {
               $("#upload").click(function() {
                   if ($("#file").val().length == 0) {
                       $("#imgMsg").html('File not specified for upload.');
                       return false;
                   }
                   $.ajax({
                       url: 'index.php?upload&destination=' + $("#destination").val() + '&allowedFiles=' + $("#allowedFiles").val(),
                       type: 'POST',
                       
                       success: function(result){
                           //$("#photo").attr('src', result);
                           $("#test").html(result);
                       }
                   });
                   //document.location.href = "index.php?upload";
                   return true;
               });
//               $("#country").change(function () {
//                   var countryId = $(this).val();
//                   $.ajax({
//                       url: 'shared/finder/_find-states-by-country-id.php?country = ' + countryId,
//                       type: 'POST',
//
//                       success: function (result) {
//                           $("#stateDiv").html(result);
//                       }
//                   });
//               });
            });
        </script>
    </head>

    <body>
        <div id="container">
            <?php include 'shared/_public-header.php'; ?>
            
            <!-- begin main content -->
            <div id="main">

                <div id="sidebar">
                    
                </div>

                <div id="content">
                    <h1>Welcome</h1>
                                <form action="submit-registration" method="post">
                        <table>
                            <tr>
                                <td>
                                        <table>
                                            <tr>
                                                <td>Surname:</td>
                                                <td><input type="text" id="surname" name="surname" value="<?php htmlOut($surname); ?>" /></td>
                                            </tr>
                                            <tr>
                                                <td>Other Names:</td>
                                                <td><input type="text" id="otherNames" name="otherNames" value="<?php htmlOut($otherNames); ?>" /></td>
                                            </tr>
                                            <tr>
                                                <td>Contact Address:</td>
                                                <td><input type="text" id="contactAddress" name="contactAddress" value="<?php htmlOut($contactAddress); ?>" /></td>
                                            </tr>
                                            <tr>
                                                <td>Country:</td>
                                                <td>
                                                    <select id="country" name="country" onChange="getState(this.value)">
                                                        <option value="">[Select Country]</option>
                                                    <?php
                                                        $commondData = new CommonData();
                                                        $countries = $commondData->getCountries();
                                                        if (sizeOf($countries) > 0) {
                                                            foreach($countries as $country) {
                                                    ?>
                                                        <option value="<?php echo $country['countryId']; ?>"><?php htmlOut($country['name']); ?></option>
                                                        <?php } } ?>
                                                    </select>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>State:</td>
                                                <td>
                                                    <div id="statediv">
                                                        <select id="state" name="state">
                                                            <option value="">[Select country first]</option>
                                                        </select>                                                
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>E-mail:</td>
                                                <td><input type="email" id="email" name="email" value="<?php htmlOut($email); ?>" /></td>
                                            </tr>
                                            <tr>
                                                <td>Phone:</td>
                                                <td><input type="text" id="phone" name="phone" value="<?php htmlOut($phone); ?>" /></td>
                                            </tr>
                                            <tr>
                                                <td>Occupation:</td>
                                                <td><input type="text" id="occupation" name="occupation" value="<?php htmlOut($occupation); ?>" /></td>
                                            </tr>
                                            <tr>
                                                <td>Office Address:</td>
                                                <td><input type="text" id="officeAddress" name="officeAddress" value="<?php htmlOut($officeAddress); ?>" /></td>
                                            </tr>
                                            <tr>
                                                <td></td>
                                                <td><input type="submit" value="Submit" /></td>
                                            </tr>
                                        </table>
                                </td>
                                <td>
                                    <span id="test"></span>
                                    <img name="photo" border="1" src="<?php echo $src; ?>" id="photo" width="120px" height="120px" /><br />
                                    <?php //displayUploadFile(10000, "image/jpeg", "uploads/member/photo/"); ?>
<!--                                    <form action="?upload" method="post" enctype="multipart/form-data">-->
                                        <input type="file" name="file" id="file" /><br />
                                        <input type="button" id="upload" value="Upload" /><span id="imgMsg"><?php echo $imgMsg; ?></span>
                                        <input type="hidden" id="destination" name="destination" value="uploads/member/photo/" />
                                        <input type="hidden" id="allowedFiles" name="allowedFiles" value="image/jpeg" />
                                        <input type="hidden" id="maximumFileSize" name="maximumFileSize" value="10000" />
<!--                                    </form>-->
                                </td>
                            </tr>
                        </table>
                    </form>
                </div>

            </div>
            <!-- end main content -->
            
            <?php include 'shared/_public-footer.php'; ?>
        </div>
    </body>
</html>


What am I getting wrong. Please help.

AnswerRe: A form data with cascading dropdown and photo for upload Pin
Mohibur Rashid24-Jan-12 22:34
professionalMohibur Rashid24-Jan-12 22:34 
GeneralRe: A form data with cascading dropdown and photo for upload Pin
awedaonline25-Jan-12 21:43
awedaonline25-Jan-12 21:43 
QuestionPHP & JavaScript integration Pin
MacRaider423-Jan-12 1:53
MacRaider423-Jan-12 1:53 
AnswerRe: PHP & JavaScript integration Pin
Graham Breach23-Jan-12 2:37
Graham Breach23-Jan-12 2:37 
GeneralRe: PHP & JavaScript integration Pin
MacRaider423-Jan-12 2:49
MacRaider423-Jan-12 2:49 
GeneralRe: PHP & JavaScript integration Pin
Graham Breach23-Jan-12 3:55
Graham Breach23-Jan-12 3:55 
GeneralRe: PHP & JavaScript integration Pin
MacRaider423-Jan-12 4:45
MacRaider423-Jan-12 4:45 
QuestionGetting the URL Minus the Query String Pin
Kevin Li (Li, Ken-un)22-Jan-12 17:49
Kevin Li (Li, Ken-un)22-Jan-12 17:49 
AnswerRe: Getting the URL Minus the Query String Pin
Peter_in_278022-Jan-12 18:24
professionalPeter_in_278022-Jan-12 18:24 
GeneralRe: Getting the URL Minus the Query String Pin
Kevin Li (Li, Ken-un)22-Jan-12 20:46
Kevin Li (Li, Ken-un)22-Jan-12 20:46 
GeneralRe: Getting the URL Minus the Query String Pin
Kevin Li (Li, Ken-un)23-Jan-12 16:09
Kevin Li (Li, Ken-un)23-Jan-12 16:09 
QuestionFinding the starting PHP script Pin
MacIntyre22-Jan-12 8:16
MacIntyre22-Jan-12 8:16 
AnswerRe: Finding the starting PHP script Pin
Luc Pattyn22-Jan-12 8:26
sitebuilderLuc Pattyn22-Jan-12 8:26 
GeneralRe: Finding the starting PHP script Pin
MacIntyre22-Jan-12 9:14
MacIntyre22-Jan-12 9:14 
GeneralRe: Finding the starting PHP script Pin
MacIntyre22-Jan-12 9:24
MacIntyre22-Jan-12 9:24 
AnswerRe: Finding the starting PHP script Pin
Luc Pattyn22-Jan-12 10:13
sitebuilderLuc Pattyn22-Jan-12 10:13 
GeneralRe: Finding the starting PHP script Pin
MacIntyre22-Jan-12 11:13
MacIntyre22-Jan-12 11:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.