Question:
i need help with javascript and php?
Jógvan
2010-11-08 13:35:11 UTC
im making a site where users can upload images using this script i found and now i need help with getting some variables out of the javascript into php variables, the variables i need is the name of the pictures and the location after uploading.

the script look like this.

$(function(){
$('#swfupload-control').swfupload({
upload_url: "upload-file.php",
file_post_name: 'uploadfile',
file_size_limit : "4096",
file_types : "*.jpg;*.png;*.gif",
file_types_description : "Image files",
file_upload_limit : 100,
flash_url : "js/swfupload/swfupload.swf",
button_image_url : 'js/swfupload/wdp_buttons_upload_114x29.…
button_width : 114,
button_height : 29,
button_placeholder : $('#button')[0],
debug: false
})
.bind('fileQueued', function(event, file){
var listitem='
  • '+
    'File: '+file.name+' ('+Math.round(file.size/4096)+' KB) '+
    '
    '+
    '

    Pending

    '+
    ' '+
    '
  • ';
    $('#log').append(listitem);
    $('li#'+file.id+' .cancel').bind('click', function(){
    var swfu = $.swfupload.getInstance('#swfupload-cont…
    swfu.cancelUpload(file.id);
    $('li#'+file.id).slideUp('fast');
    });
    // start the upload since it's queued
    $(this).swfupload('startUpload');
    })
    .bind('fileQueueError', function(event, file, errorCode, message){
    alert('Size of the file '+file.name+' is greater than limit');
    })
    .bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){
    $('#queuestatus').text('Files Selected: '+numFilesSelected+' / Queued Files: '+numFilesQueued);
    })
    .bind('uploadStart', function(event, file){
    $('#log li#'+file.id).find('p.status').text('Upl…
    $('#log li#'+file.id).find('span.progressvalue')…
    $('#log li#'+file.id).find('span.cancel').hide()…
    })
    .bind('uploadProgress', function(event, file, bytesLoaded){
    //Show Progress
    var percentage=Math.round((bytesLoaded/file.…
    $('#log li#'+file.id).find('div.progress').css('… percentage+'%');
    $('#log li#'+file.id).find('span.progressvalue')…
    })
    .bind('uploadSuccess', function(event, file, serverData){
    var item=$('#log li#'+file.id);
    item.find('div.progress').css('widt… '100%');
    item.find('span.progressvalue').tex…
    var pathtofile='view »';
    item.addClass('success').find('p.st… | '+pathtofile);
    })
    .bind('uploadComplete', function(event, file){
    // upload has completed, try the next one in the queue
    $(this).swfupload('startUpload');
    })

    });

    i'm no good with javascript so i don't really know what this means. but i need those variables.
    Three answers:
    just "JR"
    2010-11-08 13:42:58 UTC
    Unfortunately, you are not going to make it!

    Why? Because, if you can pass variables from Php to Javascript, the reverse is NOT possible!

    (Php runs BEFORE javascript, and on the server, while javascript runs on the client's machine ONLY, so variable in javascript are unknown to php).



    I must warn you that there are MANY scripts that show a progress bar while uploading, but working ones are extremely rare... It is feasible, though, (I have done it) but complex and you will have NO guarantee that it will work on all browsers...



    No, don't ask me: I have abandonned the idea: waste of time.
    anonymous
    2016-04-22 22:18:07 UTC
    You will need all three to build a site with interactive or dynamic features. HTML is the cornerstone. From there, you really should learn CSS. It is what is driving the redesign revolution that is going on right now in the world wide web. From CSS, I would then pair learning Javascript and PHP. Javascript is a client side language, and is not really considered as accessible as PHP, but is still a valuable tool. It is relatively easy to learn IF you understand programming fundementals such as functions and arrays (granted, that is over-simplifying) PHP is a server side...it is what drives SQL database applications. Extremely powerful and versitile if you can get the syntax right. PHP takes a lot of practice, but again...if you know HTML and Javascript well, it will come more naturally. Better yet, if you know another programming language, such as VB, you have a greater advantage. HTML is definately the quickest, as there are pretty much no programming concepts in it. All you need to learn is syntax, and a few basic tags. Thing is, you can learn HTML on the fly if you use a WYSIWYG editor such as Dreamweaver that builds the code for you. Dreamweaver is probably the best for this, as it doesn't add little proprietary code snippets into your work. MS Expression is a distant second...I would stay away from any freeware without doing thorough research, at least for learning purposes.
    Foster
    2010-11-08 13:49:30 UTC

    if ((($_FILES["file"]["type"] == "image/gif")

    || ($_FILES["file"]["type"] == "image/jpeg")

    || ($_FILES["file"]["type"] == "image/pjpeg")

    || ($_FILES["file"]["type"] == "image/png"))

    && ($_FILES["file"]["size"] < 16777216))

    {

    if ($_FILES["file"]["error"] == 0)

    {

    if (!file_exists("upload/" . $_FILES["file"]["uploadfile"]))

    {

    move_uploaded_file($_FILES["file"]["tmp_name"],

    "upload/" . $_FILES["file"]["uploadfile"]);

    }

    }

    }

    ?>



    this file should be named upload-file.php



    this puts files in /upload folder after uploading



    it is not displayed correctly in yahoo answers, ive uploaded the file at http://www.mediafire.com/?53awlk7bu3bbv4u


    This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
    Loading...