Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 6 of 6

Thread: PHP argument problem

  1. #1

    PHP argument problem

    Hi. I'm trying to get php to fetch some files, but I can't figure out how to do it...here is the code..
    Code:
    <?php
    require("class.easyzip.php");
    $zip = new EasyZip;
    $zip -> addFile("$_POST['Fis_lay']");
    $zip -> addFile("$_POST['Fis_txt']");
    $zip -> splitFile("site.zip", 5000000);
    echo 'Attachment has been sent Successfully.';
    ?>
    I have tried with no quotation marks, no apostrophe, quotation marks instead of apostrophe, but it always sais "Error: file does not exist" of another (very long) error on line 5. Any help is very much appreciated. Bye.
    Attached Files Attached Files
    Last edited by speedy_rudolf; October 17th, 2009 at 06:18 AM.

  2. #2
    Are you doing this from a form?

    If so can we see the form?



    If you are retrieving files from a form first the form's enctype must be set to "multipart/form-data"
    <form action="page.php" method="post" enctype="multipart/form-data">

    second you don't retrieve files from the $_POST[] global array.
    You retrieve them from the $_FILES[] global array.

    More than likely you would use $_FILES['form_field_name']['tmp_name'].


    Not only are you using the wrong array but, why are you trying to add the same file twice?
    PHP Code:
    $zip -> addFile("$_POST['fis_lay']");
    $zip -> addFile("$_POST['fis_lay']"); 
    Im guessing its because you are trying to upload multiple files from the same form correct?

    To do this the files must be stored in an array your form inputs would look like this
    Code:
    <input type="file" name="fis_lay[]" />
    the "[]" make it an array. To add multiple file upload fields to the form just duplicate that line. for example:

    to upload 2 files
    Code:
    <input type="file" name="fis_lay[]" />
    <input type="file" name="fis_lay[]" />
    Then the files would be retrieved using a multidimensional $_FILE[] global

    $_FILE['fis_lay']['tmp_name'][0] for file 1
    $_FILE['fis_lay']['tmp_name'][1] for file 2 ect....

    if your form looks like this:
    Code:
    <input type="file" name="fis_lay[]" />
    <input type="file" name="fis_lay[]" />
    try this

    PHP Code:
    <?php
    require("class.easyzip.php");
    $zip = new EasyZip;
    $zip -> addFile("$_FILES['fis_lay']['tmp_name'][0]");
    $zip -> addFile("$_FILES['fis_lay']['tmp_name'][1]");
    $zip -> splitFile("site.zip"50000);
    echo 
    'Attachment has been sent Successfully.';
    ?>
    if that doesn't work it will take someone more experienced than me to figure it out.
    Last edited by birdwing; October 16th, 2009 at 02:24 PM.

    Twitter / The Human Conditions

    biznuge: "that doesn't grammatical sense..."

  3. #3
    OK...I just figured out I should be requesting the file....so...how do I request a file? The main idea is to have the php get the files directly from the client, before they are uploaded. As you can see from the code, its purpose is to create a plitted archive on the fly. The reason for me doing this is because the server I am on doesn't accept files bigger then 5mb, and the form has a few (about 6) file inputs and to not make the user create the split archive himself, I gather the files (actually clientside filenames and locations) and create the archive directly on the server. Anyway... I repeat the question...how do I request a file? Thanks.

    PS: oh...yeah...the second one should be "Fis_txt"...anyway...the same problem aplies...

  4. #4
    Quote Originally Posted by speedy_rudolf View Post
    OK...I just figured out I should be requesting the file....so...how do I request a file? The main idea is to have the php get the files directly from the client, before they are uploaded. As you can see from the code, its purpose is to create a plitted archive on the fly. The reason for me doing this is because the server I am on doesn't accept files bigger then 5mb, and the form has a few (about 6) file inputs and to not make the user create the split archive himself, I gather the files (actually clientside filenames and locations) and create the archive directly on the server. Anyway... I repeat the question...how do I request a file? Thanks.

    PS: oh...yeah...the second one should be "Fis_txt"...anyway...the same problem aplies...

    Ah thanks for more info.. now i can tell you to try this....


    Like I said before you retrieve a file with the $_FILE[] global array

    If your form has 6 file inputs you can simplify the code with an array:

    Code:
    <input type="file" name="fis_lay[]" />
    <input type="file" name="fis_lay[]" />
    <input type="file" name="fis_lay[]" />
    <input type="file" name="fis_lay[]" />
    <input type="file" name="fis_lay[]" />
    <input type="file" name="fis_lay[]" />
    all the file inputs have the same name 'fis_lay[]' but to PHP this in an ARRAY holding 6 different files

    so the final code would be:
    PHP Code:
    <?php
    require("class.easyzip.php");
    $zip = new EasyZip;
    $zip -> addFile("$_FILES['fis_lay']['tmp_name'][0]");
    $zip -> addFile("$_FILES['fis_lay']['tmp_name'][1]");
    $zip -> addFile("$_FILES['fis_lay']['tmp_name'][2]");
    $zip -> addFile("$_FILES['fis_lay']['tmp_name'][3]");
    $zip -> addFile("$_FILES['fis_lay']['tmp_name'][4]");
    $zip -> addFile("$_FILES['fis_lay']['tmp_name'][5]");
    $zip -> splitFile("site.zip"50000);
    echo 
    'Attachment has been sent Successfully.';
    ?>
    that should retrieve all 6 file inputs using the same name. (so you don't have to create and remember 6 different input names).

    If this doesn't work.. then im out of ideas.
    Last edited by birdwing; October 16th, 2009 at 02:29 PM.

    Twitter / The Human Conditions

    biznuge: "that doesn't grammatical sense..."

  5. #5
    So....apparently, you still don't understand...the problem wasn't that I should be using an array...the problem was that I have to request the files (which are client-side) using php (which is server-side)...Let me see if I can make you understand the proccess that I need, step by step:
    1) user selects some files
    2) user submits the form.....AND....form doesn't yet upload the files to the server
    3) form calls php
    4) php stores the files in memory
    5) php creates an archive.....AND....php inserts the first file (which is still on the client computer) from memory into the archive (aka, the file is uploaded directly into the archive)
    6) when the archive reaches the set limit (ie 5mb), php splits the archive, creating another part (ie site.part2)
    7) php inserts the rest of the file from memory into archive (aka, the remainder of the files is uploaded directly into site.part2)
    8) repeat steps 6 and 7 until all files have been archived

    Hope you understood this time....And if you know how to do this client-side (create a splitted archive with 5mb per part AND THEN upload the archive/parts to the server),please tell me how. Thank you.

  6. #6
    PHP doesn't work that way. Server side languages cannot access files on the client side computer. Actually almost No web languages can access client files.. this would be a HUGE security issue!

    Example: I go to a website, and it has PHP that accesses my files and uploads them... thats an issue. The only way to modify and use client files is for them to upload them first.

    When you submit the form PHP uploads ALL the files within <input type="file" /> fields. It uploads them to a temp directory... this is still limited by the file upload max however.


    The code I gave you would work if all the files together were not over the limit... HOWEVER the way php works it would upload all the files it could and still run the code on the files it uploaded before the limit was reached...

    say you told the server to upload 5 files... the first 2 files make it and halfway through the 3rd the max upload is reached.

    It will upload the first 2 and depending on how the script you right handles errors it should still compile the first 2 files into the archive.



    But this is not what you want... what you are looking for is impossible with PHP probably with any type of web code. Someone with more experience will have to verify that last part... but i know for sure that PHP and Javascript do not allow it.

    Java applets might allow you to do this.... but im not sure.




    sry for the misunderstanding.

    Twitter / The Human Conditions

    biznuge: "that doesn't grammatical sense..."

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012