Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

I/O error (php Session)
  • Heeeeelp!!
    I'm using Uploadify perfectly in a site i'm developing and its works great. The problem began when i trully implemented it with the PHP SESSION.
    The site is a 'traveler comunity' where you con upload your pics. So you sign in, go to the upload section and begin the files upload queue. It uploads some files fine, but then it starts returning I/O error in each file up to the last one.

    I've read the post "Using sessions & tricking Basic Authentication" (http://www.uploadify.com/forum/viewtopic.php?f=5&t=43&p=842&hilit=session#p842)
    and i made wath they say, but the same error appears..

    Please!! Help me!! I need this to get working now, otherwise my client is going to kill me.
    Here are my codes:

    The Upload page (JS)

    $('#fileInput2').fileUpload({
    'uploader':'uploadify/uploader.swf',
    'script':'uploadify/upload.php',
    'cancelImg':'uploadify/cancel.png',
    'folder':'archivos/album',
    'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
    'fileDesc': 'Archivos de imágenes',
    'buttonText': 'Examinar',
    'sizeLimit': '7168000',
    'auto':true,
    'multi':true,
    'scriptData': {'session_name': '<?= session_id(); ?>'},
    'onComplete' : function(event, queueID, fileObj, response, data) {
    $('div#archivos').append(\"- <b>\" + response + \"</b> <span style='color: green;'>ok!</span><br />\");
    $('#uploadhidden').val($('#uploadhidden').val() +response+ ',');
    }


    - UPLOAD.PHP:

    session_id($_GET['session_name']);
    session_start();
    if ($_SESSION['mydata'] != 'whatever') {
    header(\"HTTP/1.0 404 Not Found\");
    exit;
    }
    if (!empty($_FILES)) {
    $upload_dir = \"../archivos/album/\";
    $temp_name = $_FILES['Filedata']['tmp_name'];
    $file_name = $_FILES['Filedata']['name'];
    $file_path = $upload_dir.$file_name;
    $new_file_name=$file_name;
    $ver=0;
    while ( file_exists($file_path) ) {
    $ver++;
    $new_file_name = \"[\".$ver.\"]\".$file_name;
    $file_path = $upload_dir.$new_file_name;
    }
    move_uploaded_file($temp_name, $file_path);
    }

    echo $new_file_name; // Important so upload will work on OSX


    I'll be waitnig any help. Thanks!
  • It would appear your missing the vital session starting call on your calling php page.

    This is assuming you haven't moved the fileUpload() into a seperate js file.

    make sure you add this as the very first call in the file that includes the fileUpload().
    <?php 
    session_start();
    $_SESSION['mydata'] = 'whatever';
    ?>


    You should also change mydata and whatever to something more specific to your website.
  • Hi TravisN. Thanks for helping me.
    I have the js code in the same page. I suposed that 'mydata' and 'wahtever' was irrelevant, only for cheking that the session is active.

    What info should i use here?
    $_SESSION['mydata'] = 'whatever';

    For example: $_SESSION['user_id'] = ????
    Thanks!
  • You got it, 'mydata' and 'whatever' can be what ever you like. It is just so that you have something to check against on the other end. Just make sure you call it the same on both ends.
  • Still having the same error. Now, I think it's a problem with the uploader (flash-php-session) and not of my code.
    I did all as you said, but still continues without working.
    Any other help?

    Thanks a lot.
  • Try changing
    session_id($_GET['session_name'])
    to
    session_id($_REQUEST['session_name'])
    . Doesn't Uploadify use POST anyway?
  • Hi strzelecki. I've made what you said, but.. the same error appears.
    I'm using POST in the form.

    Could the error be here: ??
    $_SESSION['mydata'] = 'whatever';

    I asked TravisN what info should i use there, but he didn't answer me.
    I've suposed if i put 'mydata' and 'whatever', and then in the UPLOAD.PHP i look for 'mydata' and 'whatever' it should works. Should it? If not, what info should i use there instead of 'mydata' and 'whatever' ???

    Thanks for yout time. I'm going crazy with that.
  • I take it if you remove the session check from your upload.php it works? If it does can you post your files.
  • Hi there! Hi TravisN. I solved the problem!!! Thank you so much for your time.
    It wasn't the php session! I'm sorry, but i discovered it was because of the simultanious upload. I limited it to a smaller number and now works great! I think you sould notice that in some place of the docs. I don't know if it's a limitation with my server, but...

    Thank you so much again! That's the best uploader i've ever seen!
  • Hi Travis,

    ive been having the same PHP SESSION issue mentioned in several threads but have been unsuccessful fixing the problem. problem is that it seems that my SESSION in the upload.php file is empty. i've tried passing the session id, name in several different ways but none are able to start the session properly.

    index.php - client side

    $('#assignmentFiles').fileUpload({
    'uploader': 'uploader.swf',
    'script': 's_uploader.php',
    'folder': '../../FILES',
    'cancelImg': 'lib.img/remove.png',
    'multi': true,
    'scriptData':{'request':'assignment_files', 'assignment_id':'\".$assignment_id.\"', 'PHPSESSID':'\".session_id().\"'}


    s_uploader.php - server side

    session_id($_GET[\"PHPSESSID\"]);

    session_start();

    if(!is_numeric($_SESSION['session_user_id']))
    {
    header(\"HTTP/1.0 404 Not Found\");
    exit();
    }


    as mentioned by other users the files upload properly, but being that im trying to log certain information in a DB, i need the session data for this. ive read and tried all other SESSION threads i've found but with no success... is there anything i could be missing? other people seem to have been able to get this working.. thanks in advance!

    Diego
  • Well after a lot of research seems the issue was in the way my sessions were being stored. by default they are stored in a system file(text) and being that my application is hosted on load balanced servers when i called the
     session_id($_GET['session_name'])
    it could not find the session file being that it was in a different server. my solution was to implement SESSION storage on the DB instead. this took me about 1.5 hours to implement following a modified (for my purpose)version of the SESSION HANDLER shown below http://www.devshed.com/c/a/PHP/Storing-PHP-Sessions-in-a-Database/7/

    so what i do now differently in the s_uploader.php file is

    $sess = new SessionManager($connection);

    session_id($_GET[\"PHPSESSID\"]);
    session_start();


    of course after defining the SessionManager class by following the example in the link provided above.

    hope this can help someone that may have been in my situation.
  • 'scriptData':{'request':'assignment_files', 'assignment_id':'".$assignment_id."', 'PHPSESSID':'".session_id()."'}

    session_id() is php function not JS or JQ. So to call it I think it needs to be something like this:

    'scriptData':{'request':'assignment_files', 'assignment_id':'".$assignment_id."', 'PHPSESSID':'<?php echo session_id();?>'}

    This works fine for me

    Regards

    Nasko
  • Naskoo is right. The call to session_id() needed to be inside php echo tags.
  • Thanks for posting such useful information.
    Cheer :D
    simulation credit auto