Read contents of local file?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

If your form looks like:

Code: Select all

<form name=&quote;myform&quote; method=&quote;post&quote; action=&quote;http://home.ripway.com/2005-6/328190/uploadtest.php&quote; enctype=&quote;multipart/form-data&quote;>
Then it should work...?
User avatar
IceMetalPunk
Forum Commoner
Posts: 71
Joined: Thu Jul 07, 2005 11:45 am

Post by IceMetalPunk »

Well that is what it looks like, and it doesn't work.... Can anyone else help?

-IMP ;) :)
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Is File Upload enabled on your machine?

Code: Select all

phpinfo();
Look for:

Code: Select all

file_uploads	On	On
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

hawley is right on target.

how big is the file you're trying to upload? If it's over 2MB then you've exceeded what the default is set for in php.ini. You need to change the max upload size and the max post size...
User avatar
IceMetalPunk
Forum Commoner
Posts: 71
Joined: Thu Jul 07, 2005 11:45 am

Post by IceMetalPunk »

That's the problem! file_uploads is off.... but this is on another server.... is it possible to change the settings for this through PHP?

-IMP ;) :)
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

ini_set()

EDIT: although I'm not sure you can do it with that directive
User avatar
IceMetalPunk
Forum Commoner
Posts: 71
Joined: Thu Jul 07, 2005 11:45 am

Post by IceMetalPunk »

Hmmm... now my code looks like this:

Code: Select all

<html><body>
<?php
ini_set("file_uploads","1");
echo '<HR><PRE>'; print_r($_FILES); echo '</PRE>';
?>
And it STILL returns a blank array....Does this mean that my host (Ripway) doesn't allow uploads from user PHP scripts?

-IMP ;) :)
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

IceMetalPunk wrote:Does this mean that my host (Ripway) doesn't allow uploads from user PHP scripts?
I suppose it could?? contact them and find out ;)
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

Hello friend! If you are still having trouble you may find the answers you need in the script I am posting. It is a complete and working but compact script which shows everything needed for file upload and save operations.

Code: Select all

<?php

// Fill this in. Must end with a slash / and it needs to be created and you need write permission 0777
$uploads_directory = $_SERVER['DOCUMENT_ROOT'] . '/images/';

//Find url: self
$self = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];

// Make form
echo <<<END
<form  action="$self" enctype="multipart/form-data" method="post">
<input name="file[]" type="file" id="file[]"><br>
<input name="file[]" type="file" id="file[]"><br>
<input name="file[]" type="file" id="file[]"><br>
<input type="submit" name="Submit" value="Submit"></form><br>
END;
//Save uploaded files
$i = 0;
while(isset($_FILES['file']['name'][$i])){
    if(!empty($_FILES['file']['name'][$i])){
      if($_FILES['file']['error'][$i]==0){
       if(!file_exists($uploads_directory . $_FILES['file']['name'][$i])){
          if(is_uploaded_file($_FILES['file']['tmp_name'][$i])){
               if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $uploads_directory . $_FILES['file']['name'][$i])) {
                    print("Success saving the file '{$_FILES['file']['name'][$i]}' (file
                    number '$i' in the array) in the directory '$uploads_directory' <br>");
               }else{
                    print("Failure saving the file '{$_FILES['file']['name'][$i]}' (file
                    number '$i' in the array) in the directory '$uploads_directory' <br>");
               }
          }
       }else{
          print("A file named '{$_FILES['file']['name'][$i]}' (file number '$i' in
          the array) already exists in the directory '$uploads_directory'. Please rename
          your file and try again <br>");
        }
       }
      }
  $i++;
}
?>
Post Reply