Jump to content

OtagoHarbour

Members
  • Posts

    118
  • Joined

  • Last visited

Posts posted by OtagoHarbour

  1. I was not sure whether this question belongs here of in the PHP forum since my problem may be with one or the other or both.

     

    I use the following html and php code to select and upload multiple files.HTML

         <form action="uploadFiles.php" method="post" enctype="multipart/form-data">        <label for="file">Filename:</label>        <input type="file" name="file[]" multiple="multiple"/></br>        <input type="submit" name="submit[]" value="submit" />     </form>

    uploadFiles.php

        <?php        if(isset($_POST['submit']))        {           if ($_FILES["file[]"]["error"] > 0)           {                echo "Error: " . $_FILES["file[]"]["error"] . "<br>";            }            else            {                $numFilesUploaded=count($_FILES['file']['name']);                echo "No. files uploaded : ".$numFilesUploaded."<br><br>";                for ($inc=0; $inc<$numFilesUploaded; ++$inc){                    echo "File " . $inc . ": " . $_FILES["file"]["name"][$inc] . "<br>";                    echo "Upload: " . $_FILES["file"]["name"][$inc] . "<br>";                    echo "Type: " . $_FILES["file"]["type"][$inc] . "<br>";                    echo "Size: " . ($_FILES["file"]["size"][$inc] / 1024) . " kB<br>";                    echo "Stored in: " . $_FILES["file"]["tmp_name"][$inc];                    echo "<br><br>";                }            }        }    ?>

    If I select 2 files, each having names of character length 8, the code works fine. However, when I select files with names of character length 32, $_POST is an empty array. What is the best way to upload multiple files where the file names may be long?

     

     

    I ran phpinfo() and it did indeed say "This server is protected with the Suhosin Patch 0.9.10 ..."

     

    Some people have suggested that it may be a problem with the file size. However, I never get to even try to upload files since the names are not properly passed to the PHP code if the filenames are too long. Also, I have modified /etc/php5/apache2/php.ini to allow the upload of files larger than the files I am trying to upload. Also, I do not have this problem if I shorten the names of the files I am having trouble with.

     

    Many thanks in advance for any help.

     

  2. I tried that code except without

    <!doctype html>

    since it is a PHP file. I found that

    if(isset($_POST['submit']))

    returns false. I don't know why this is since this is my form code and I selected 2 files.

    <form action="uploadFiles.php" method="post" enctype="multipart/form-data">        <label for="file">Filename:</label>        <input type="file" name="file[]" multiple /><br>        <input type="submit" name="submit" value="submit" /></form>

    Thanks,

    OH

  3. When you select multiple files in the way you're doing it, the "name", "type", etc are arrays and those arrays indexes will contain the info you're looking for.By adding a [0] to the code below, you'll access the first index of that array:

    if ($_FILES["file"]["error"][0] > 0)    {        echo "Error: " . $_FILES["file"]["error"][0] . "<br>"; // this would check for error only for that first image selced    }    else    {          echo "No. files uploaded : ".count($_FILES['file']['name'])."<br>";          echo "Upload: " . $_FILES["file"]["name"][0] . "<br>"; // this selects the name of the first image selected          echo "Type: " . $_FILES["file"]["type"][0] . "<br>";// this selects the type of the first image selected          echo "Size: " . ($_FILES["file"]["size"][0] / 1024) . " kB<br>"; // this gets the size of the first image selected          echo "Stored in: " . $_FILES["file"]["tmp_name"][0]; // // this gets the temp_name of the first image selected    }

    If you do a print_r on $_FILES["file] like this: print_r($_FILES["file"]) and go look in the source code of the web page, you'll get a better idea of how the arrays look. Here's an example:Array( [name] => Array ( [0] => 400lomoupmi.png [1] => 400saraship.png ) [type] => Array ( [0] => image/png [1] => image/png ) [tmp_name] => Array ( [0] => /private/var/folders/f8/fswjbfl94cj77tbw053hcdb40000gn/T/phpnTzAq0 [1] => /private/var/folders/f8/fswjbfl94cj77tbw053hcdb40000gn/T/phpV97ABJ ) [error] => Array ( [0] => 0 [1] => 0 ) => Array ( [0] => 213597 [1] => 181958 ))

     

    I selected 2 images as you can see. You can use a foreach loop to loop through the arrays to get the values for each to display on the webpage.

     

    Thank you for your reply but it still does not appear to be working properly.

     

    I tried

     

     

        echo "_FILES[file]: " . print_r($_FILES['file']) . "<br>";    if ($_FILES["file"]["error"][0] > 0)    {        echo "Error: " . $_FILES["file"]["error"][0] . "<br>"; // this would check for error only for that first image selced    }    else    {          echo "No. files uploaded : ".count($_FILES['file']['name'])."<br>";          echo "Upload: " . $_FILES["file"]["name"][0] . "<br>"; // this selects the name of the first image selected          echo "Type: " . $_FILES["file"]["type"][0] . "<br>";// this selects the type of the first image selected          echo "Size: " . ($_FILES["file"]["size"][0] / 1024) . " kB<br>"; // this gets the size of the first image selected          echo "Stored in: " . $_FILES["file"]["tmp_name"][0]; // // this gets the temp_name of the first image selected    } 

     

    and got

     

     

     

    _Files[file]: 1No. files uploaded: 0Upload:Type:Size: 0 kBStored in:
  4. I am trying to modify the code given here to upload multiple files. The code I use is as follows.

    ?>    <form action="uploadFiles.php" method="post"        enctype="multipart/form-data">        <label for="file">Filename:</label>        <input type="file" name="file[]" multiple><br>        <input type="submit" name="submit" value="Submit">    </form><?

    uploadFiles.php has the following code

    <?php    if ($_FILES["file"]["error"] > 0)    {        echo "Error: " . $_FILES["file"]["error"][0] . "<br>";    }    else    {          echo "No. files uploaded : ".count($_FILES['file']['name'])."<br>";          echo "Upload: " . $_FILES["file"]["name"][0] . "<br>";          echo "Type: " . $_FILES["file"]["type"] . "<br>";          echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";          echo "Stored in: " . $_FILES["file"]["tmp_name"];    }?>

    I select 2 files in the browser window and get the following output.

    No. files uploaded: 0Upload:Type:Size: 0kBStored in:

    I cannot understand why I am getting 0 files when I selected 2 files.

     

    Thanks,

    OH.

     

  5. I'm glad it helped. I did know you were doing JavaScript because you were using an AJAX object. The AJAX object has a place to specify GET or POST. It might still be worth looking at. If you borrowed the loadXMLDoc function here, notice that it's preprogrammed with GET. It doesn't have to be; and if I understand your situation, it probably should not be. Any server request that changes data on the server should be a POST request.
    Yes. That was the problem. Thanks again.
  6. It sounds like the original doc is being cached. If you are using the GET request change it to POST. On the server side, you might send out these headers before sending your data: "Cache-Control: no-cache, must-revalidate""Pragma: no-cache"
    Sorry. I should have mentioned that I am doing everything in JavaScript with some HTML. However you are certainly right about the caching causing the problem. I put the following code
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" /><meta http-equiv="Pragma" content="no-cache" />

    in the head section of index.html and that appears to have solved the problem. Thank you very much for you help,Peter.

  7. I used loadXMLDoc to load an XML file onto my web page. I then saved different contents to a file of the save name. When I reloaded the file with loadXMLDoc, I got the original contents instead of the new contents. I deleted the file and then save the new contents to the file with the same name. Reloading still gave me the old contents. I then changed the name of the file. This time loading the file with loadXMLDoc gave me the new contents. Does loadXMLDoc remember the contents that was loaded from a file with a given name and not bother reloading the contents if I present it with a file of the same name albeit different contents? After modifying the file, I looked at the XML code and the contents were modified after the first modification.

  8. I would like to use PHP to put a vertical space on a web page.

    echo "<br \><br \><br \><br \>";

    works fine on FireFox but probably breaks several rules in relation to strict xhtml and may not work as well on other browsers. Is there are more standard/correct/robust way of doing this? Thanks,Peter.

  9. this is it
    <a href="http://192.168.1.4/about.php">About</a>

    $_SERVER['REMOTE_HOST'] will evaluate value only in php context <a href="<?php echo $_SERVER['REMOTE_HOST'];?>/about.php">About</a>

    Thanks. I'll try that and see if it works. The problem with what I had initially was that I did not specify the contect so it took the default. Thanks,Peter.
  10. for now it is taking it as relative url.prepend the prtocol if you want to point to different site. if you want to the url being changed if your site adrees change you can add $_SERVER['REMOTE_HOST'] in the place of host
    I tried chaning the php code to
    <li><a href="$_SERVER['']/192.168.1.4/about.php">About</a></li>

    but now it tries to accesshttp://localhost//$_SERVER['']/192.168.1.4/about.php I want it to just try to access192.168.1.4/about.php without all the preceeding stuff. Thanks,Peter.

  11. I am hosting a web site from home. My system has two layers: a web server (running Ubuntu 11.04) that is port forwarded through port 80 and has only index.php on var/www and an application server (running Ubuntu 11.10) that has everything else and is set up to only talk to the web layer server. index.php has the following line of code.

    <li><a href="192.168.1.4/about.php">About</a></li>

    This is a menu item that is supposed to call about.php which is located in var/www on the application server which has the local IP address 192.168.1.4. However, when I click the button associated with this menu item, it tries to access http://localhost/192.168.1.4/about.php and gives the error message

    The requested URL /192.168.1.4/about.php was not found on this server.

    If I go to the address box and manually delete the http://localhost/ part so the address box simply says 192.168.1.4/about.php then the about.php page on the application server shows up. Subsequently, when I click on a menu button associated with index.php then everything works fine. It seems like it starts by adding http://localhost/ to the specified address until I manualy delete it and then it leaves it out by default. The real problem comes when I try to access my site from another computer. I type in my domain name, say whatever.com, and the index.php page shows up. However when I click on the menu button, it tries to access http://whatever.com/...8.1.4/about.php and gives an error message. When I go to the URL box and manually delete http://whatever.com/, everything works fine. However I do not want the user to have to do this. Also, I am doing this from another computer on my home network so I am not sure what would happen from a remote computer. What is the best way to get the index.php file to simply use 192.168.1.4/about.php and not localhost/192.168.1.4/about.php, whatever.com/192.168.1.4/about.php etc. Many thanks in advance,Peter.

×
×
  • Create New...