Hi,
I have jQuery 1.2.3 and the Form plugin 2.07.

I don't know if I'm doing some wrong here, my PHP code seems fine but
here's the problem. If you just upload an image (don't fill OR fill in
the text fields) it seems to skip all my PHP validation and just
reload the page into the output DIV on success. Now this isn't right
and I don't know why.

<script src="/_j/jquery/jquery-1.2.3.min.js" type="text/javascript"></
script>
<script src="/_j/jquery/jquery.form.js" type="text/javascript"></
script>
<script type="text/javascript">
{literal}
        $(document).ready(function(){
                $('#uploadForm').ajaxForm({
        beforeSubmit: function(a,f,o) {
            o.dataType = 'html';
            $('#uploadOutput').html('Submitting...');
        },
        success: function(data) {
            var $out = $('#uploadOutput');
            $out.append('<div><pre>'+ data +'</pre></div>');
        }
    });
        });
{/literal}
</script>
<div class="col">
        <div id="uploadOutput">

        </div>
        <form id="uploadForm" action="/im/upload/go/" method="POST"
enctype="multipart/form-data">
                <div>
                        <label>ALT Title:</label>
                        <input name="alt" type="text" maxlength="100" 
class="txtbox" />
                </div>
                <div>
                        <label>Description:</label>
                        <input name="description" type="text" maxlength="250"
class="txtbox" />
                </div>
                <div>
                        <label>Tags:</label>
                        <input name="tags" type="text" maxlength="250" 
class="txtbox" />
                </div>
                <div>
                        <label>Image:</label>
                        <input name="imupload" type="file" class="txtbox" />
                </div>
                <div class="btnbox">
                        <button name="upload" type="submit">Upload</button>
                </div>
        </form>
</div>

if($p[0] == 'go' && isset($_POST['upload'])) {
                        echo 'here1';
                        if($_POST['alt'] != '' && $_POST['description'] != '' &&
$_POST['tags'] != '') {
                                echo 'here2';
                                
if(is_uploaded_file($_FILES['imupload']['tmp_name'])) {
                                        var_dump($_FILES);
                                        if($_FILES['imupload']['type'] == 
'image/jpeg' || $_FILES['image']
['type'] == 'image/png' || $_FILES['image']['type'] == 'image/gif' ||
$_FILES['image']['type'] == 'image/pjpeg') {
                                                $filename = 
$this->_make_unique_file(10) . '.jpg';
                                                $new_path = $path . 'raw\\';

                                                $size = 
getimagesize($_FILES['imupload']['tmp_name']);

                                                if($size[0] >= 320 && $size[1] 
>= 240) {
                                                        
if(!copy($_FILES['imupload']['tmp_name'], $new_path .
$filename)) {
                                                                
unlink($_FILES['imupload']['tmp_name']);
                                                                throw new 
Exception;
                                                        }

                                                        $desiredw = 100;
                                                        $desiredh = 75;

                                                        include(FRAMEWORKPATH . 
'im/controllers/image.php');
                                                        $image = new 
image($new_path, $filename);
                                                        if($image->handle) {
                                                                
$image->resample = true;
                                                                $thumb = 
$image->resize_image(100, 75);

                                                                $output = 
$image->create_file($thumb, $path . 'thumb\\',
$filename);
                                                                //$output = 
$image->output_image($thumb);

                                                                $output = 
$image = null;

                                                                echo '<div 
class="alert success" style="display:
block;"><p>Success</p></div>';
                                                        } else {
                                                                echo '<div 
class="alert error" style="display:
block;"><p>Error - problem opening image</p></div>';
                                                        }
                                                } else {
                                                        echo '<div class="alert 
error" style="display: block;"><p>Error
- image too small</p></div>';
                                                }
                                        } else {
                                                echo '<div class="alert error" 
style="display: block;"><p>Error
- upload an image</p></div>';
                                        }
                                } else {
                                        echo '<div class="alert error" 
style="display: block;"><p>Error -
fill in the fields</p></div>';
                                }
                        } else {
                                echo '<div class="alert error" style="display: 
block;"><p>Error -
fill in the fields</p></div>';
                        }
                } else {
                        echo 'here';
                        $this->smarty->display(FRAMEWORKPATH . 
'im/templates/upload.tpl');
}

Reply via email to