Variable Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fangonk
Forum Newbie
Posts: 21
Joined: Thu May 14, 2009 6:43 am

Variable Problem

Post by fangonk »

I have three files. The first (dropdown.php) contains an uploader and a dropdown menu that is dynamically populated from an xml files. The second file (uploader.php) is the script that runs the flash uploader in the first file. This uploader script also writes all of the filenames of the uploaded files to an xml file. The last file (xmlnamer.php) records the user's selection from the dropdown menu in the first file to a variable ($dor). I want to use the user's selection from the drop down menu to define the name of the xml file where the names of all the uploaded files are recorded. I hope this isn't too confusing:

dropdown.php:

Code: Select all

 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Uploadify scriptData Sample</title>
 
<link rel="stylesheet" href="uploadify/uploadify.css" type="text/css" />
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery.uploadify.js"></script>
<script type="text/javascript">
 
$(document).ready(function() {
 
    $("#fileUpload2").fileUpload({
        'uploader': 'uploadify/uploader.swf',
        'cancelImg': 'uploadify/cancel.png',
        'script': 'uploadify/upload.php',
        'folder': 'files',
        'multi': true,
        'buttonText': 'Select Files',
        'checkScript': 'uploadify/check.php',
        'displayData': 'speed',
        'simUploadLimit': 4
    });
});
 
</script>
 
<script type="text/javascript">
        $(document).ready(function(){
            $.ajax({
                type: "GET",
                url: "galleries.xml",
                dataType: "xml",
                success: function(xml) {
                    var select = $('#mySelect');
                    $(xml).find('category').each(function(){
                        var title = $(this).find('title').text();
                        select.append("<option>"+title+"</option>");
                    });
                    select.children(":first").text("please make a selection").attr("selected",true);
                }
            });
        });
</script>
 
</head>
<body>
        <h2>Multiple File Upload</h2>
        <div id="fileUpload2">You have a problem with your javascript</div>
            <form action="uploadify/xmlnamer.php" method='get'>
            <select name="selectBox" id="mySelect" onchange="this.form.submit()">
                <option>loading</option>
            </select>
        </form>
        <a href="javascript&#058;$('#fileUpload2').fileUploadStart()">Start Upload</a> |  <a href="javascript&#058;$('#fileUpload2').fileUploadClearQueue()">Clear Queue</a>
 
</body>
</html>
 
upload.php:

Code: Select all

 
<?php
     
    if (!empty($_FILES)) {
        $tempFile = $_FILES['Filedata']['tmp_name'];
        $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';
        $targetPath =  str_replace('//','/',$targetPath);
        $targetFile =  $targetPath . $_FILES['Filedata']['name'];
        move_uploaded_file($tempFile,$targetFile);
    }
 
    $imgsize = getimagesize($targetFile);
    switch(strtolower(substr($targetFile, -3))){
        case "jpg":
            $image = imagecreatefromjpeg($targetFile);    
        break;
        case "png":
            $image = imagecreatefrompng($targetFile);
        break;
        case "gif":
            $image = imagecreatefromgif($targetFile);
        break;
        default:
            exit;
        break;
    }
 
    $width = 80; //New width of image    
    $height = $imgsize[1]/$imgsize[0]*$width; //This maintains proportions
 
    $src_w = $imgsize[0];
    $src_h = $imgsize[1];
        
 
    $picture = imagecreatetruecolor($width, $height);
    imagealphablending($picture, false);
    imagesavealpha($picture, true);
    $bool = imagecopyresampled($picture, $image, 0, 0, 0, 0, $width, $height, $src_w, $src_h); 
 
    if($bool){
        switch(strtolower(substr($targetFile, -3))){
            case "jpg":
                header("Content-Type: image/jpeg");
                $bool2 = imagejpeg($picture,$targetPath."Thumbs/".$_FILES['Filedata']['name'],80);
            break;
            case "png":
                header("Content-Type: image/png");
                imagepng($picture,$targetPath."Thumbs/".$_FILES['Filedata']['name']);
            break;
            case "gif":
                header("Content-Type: image/gif");
                imagegif($picture,$targetPath."Thumbs/".$_FILES['Filedata']['name']);
            break;
        }
    }
 
    imagedestroy($picture);
    imagedestroy($image);
 
    echo '1'; // Important so upload will work on OSX
 
 
$str = $_FILES['Filedata']['name'];
$fp = fopen($dor, 'a+');
fwrite($fp, $str);
fclose($fp);
echo '1';
?>
 
xmlnamer.php:

Code: Select all

 
<?php
$dor = $_GET["selectBox"];
header("Location:http://mydomain.com/imgupload/dropdown.php"); 
?>
 
No XML file is being created at upload because (I suspect) upload.php doesn't recognize the $dor variable. Im really new to php so I am sure this must be some sort of really simple error. Any suggestions?
Last edited by Benjamin on Tue May 26, 2009 10:09 am, edited 1 time in total.
Reason: Changed code type from text to php.
Post Reply