views:

207

answers:

2

For the love of pete I can't get it to accept any variables into to my SQL db. If I put static info it works. I can't seem to pass any paramaters over with scriptdata and it makes it more challenging because I'm using smarty template system on top.

I was trying to do this.

 {literal}
<script type="text/javascript">
jQuery(document).ready(function() {
    jQuery("#fileUpload").uploadify({

        'scriptData'     :{'alb_id': '{/literal}$alb_id{literal}','mem_id': '{/literal}$info.mem_id{literal}'},
        'uploader': '/ajax/upload/uploadify.swf',
        'cancelImg': '/ajax/upload/cancel.png',
        'script': '/ajax/upload/uploader.php',
        'folder': 'photos',
        'multi': true,
        'displayData': 'speed',
        'fileDesc'  : 'Image Files',
        'fileExt': '*.jpg;*.jpeg;',
        'simUploadLimit': 200,
        'width'          : 130,
        'queueID'        : 'fileQueue',
        'buttonImg': '/themes/mytheme/gfx/buttons/but_browse.gif'       
    });

});
</script>
{/literal}

In my template file. The upload part works fine. Just not the mysql. I am using a function built into the script to resize images for thumbnailes and what not and build a directory. All that works. It just won't pass any variables to the db.

include_once("../../includes/config/config.inc.php");
    //load libraries
include(DOC_ROOT."/libraries.php");


$conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS,1);
mysql_select_db(SQL_DB,$conn);

$alb_id = $_REQUEST['alb_id'];
$mem_id = $_REQUEST['mem_id'];  


if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];

        $extension = ".jpeg";
        $photo = build_thumbnailes($tempFile,$extension);

        $sql ="INSERT INTO `photos`(`mem_id`, `photo`, `photo_med`, `photo_small`, `approved`,`posted`, `upload_date`) 
        VALUES 
        ('$alb_id', '".$photo["ex"]."', '".$photo["med"]."','".$photo["small"]."' , '1', time(), time())";
        mysql_query($sql) or die(mysql_error());

Please help if you can. I'm going crazy with this thing. Thanks.

+1  A: 

Well I don't know if this is the "answer" but I do see a couple of problems.

  1. In your template you have:

'scriptData' :{'alb_id': '{/literal}$alb_id{literal}','mem_id': '{/literal}$info.mem_id{literal}'},

Your smarty variables $alb_id and $info.mem_id are going to be passed literally (instead of their values). You need:

 'scriptData':{'alb_id': '{/literal}{ $alb_id }{literal}','mem_id': '{/literal}{ $info.mem_id }{literal}'},

Secondly you should be checking if your file is truly an uploaded file in your PHP. Instead of:

if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];

Use:

if (is_uploaded_file($_FILES['Filedata']['tmp_name'])) {
    $tempFile = $_FILES['Filedata']['tmp_name'];

I really suspect you aren't getting the data from the form you think you're getting. How do you know the upload is working? How do you know the values were passed from the form? You might want to print out the variables from the form to see if you're really getting what you expect.

Do you get an error from MySQL? Or is it that the data just doesn't show up. Providing some more info might get you some better answers here.

Cfreak
I will change the script data part. Thanks for that. The thumbnail function is working because I see the directories being created with the 3 different sizes for the images. I can see all the new files via ftp. So that part works. The DB part works too if I actual put in Text data instead of vars. It's not passing any Var for some reason for the 3 photo sizes names to the DB or the Requests at the top.
Pjack
Some how, it's working now. Thanks for the correction on the smarty Vars. I believe my SQL syntax was wrong in the php file but it wasn't getting any errors in the logs or anything. The only part that wasn't working was the mysql and now it is doing both. Thanks for the help.
Pjack
A: 

A easy way to test your script is create a normal file input in a normal form wich action you point to upload.php . So if there is an error you will see it then.

Is it possible build_tumbnailes is trowing an error?

Iznogood