GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 28-Mar-2004, 07:41
PenguinJr PenguinJr is offline
New Member
 
Join Date: Feb 2004
Posts: 19
PenguinJr is on a distinguished road
Question

File editing and uploading?


Hi guys,

I'm very unsure on how to go about achieving this.
I'd like to have a page where a user is able to:
1. Upload a file (.doc file, .txt file, images) and preferrably store these files somewhere in a sub-folder (all are done through a web interface, not ftp).
2. Post texts - Just one big piece of text, and the ability to edit it themself (as in update). So its like one big textbox.

I'm open to any solutions.

Thank you in advance for any help. =).
  #2  
Old 28-Mar-2004, 10:55
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hello PenguinJr,

I am doing some of this kind of thing right now. I am not sure how you want to approach it. I am doing it through cgi server scripts written and compiled in c.
  1. Uploading files can be done through the input keyword like:
    HTML Code:
    <input TYPE="file" NAME="in_file" ACCEPT="text/html">
    Thats the easy part. From there you need to decide how you want to extract the information upon submit. I have written a c routine to do this, but it is very alpha. Here is my current (somewhat broken) implementation. I should have this up and running properly early next week, but it will atleast show you what a file input form looks like. There is also some perl scripts I have found that will parse a submit cgi file.
  2. This is a bit more tricky. First of all you are going to have to have some sort of user verification system. In addition, you will need to have some sort of database running in order to dynamically store and retrieve information. Mysql with PHP is extremely helpful here, if you have any experience with either. I run a self-made database backend for these type of things.

The biggest question is what kind of scripting/programming experience do you have? There are several ways to do this, but you should use a language/approach that you have some experience with.

Good Luck!
d
  #3  
Old 28-Mar-2004, 18:46
PenguinJr PenguinJr is offline
New Member
 
Join Date: Feb 2004
Posts: 19
PenguinJr is on a distinguished road
Hmmmmmmmm....

I'm more inclined to doing PHP for both..

and for no.2. do you know of a way for it to be linked to a .txt file? would make it easier. But php/mysql sounds good too.
  #4  
Old 31-Mar-2004, 07:21
gardolas's Avatar
gardolas gardolas is offline
Awaiting Email Confirmation
 
Join Date: Jan 2004
Location: Devon
Posts: 11
gardolas is on a distinguished road
For part 1 of your question try the following:

PHP Code:

<?PHP

$uploaddir = "users"; // set this to your upload directory make sure to set permissions to 777

if ($_FILES['File']) { // if a file has been selected
     echo "File name:" . $_FILES['File']['name'] . "<br />";
     echo "File Size:" . $_FILES['File']['size'] . "<br />";
     echo "File Type:" . $_FILES['File']['type'] . "<br />";
     echo "Error Code:" . $_FILES['File']['error'] . "<br />";
     
     // validate the file
     $input_errors = array();
     
     $allowed_ext = "jpg, gif, png, txt"; // file extensions that can be uploaded
     $max_size = "50000"; // in bytes i.e. 50000 = 50KB
     $max_height = "300"; // height in pixels (leave empty if not uploading images)
     $max_width = "300"; // width in pixels (leave empty if not uploading images)

     // Check Entension
     $extension = pathinfo($_FILES['File']['name']);
     $extension = $extension[extension];
     $allowed_paths = explode(", ", $allowed_ext);
     for($i = 0; $i < count($allowed_paths); $i++) {
          if ($allowed_paths[$i] == "$extension") {
               $continue = "TRUE";
          }
     }

     if ($continue == "TRUE") {
     
          // Check File Size
           if($_FILES['File']['size'] > $max_size) {
               $input_errors[] = "The file is bigger than the maximum allowed size";
           }

          // Check Height & Width
           if ($max_width && $max_height) {
               list($width, $height, $type, $w) = getimagesize($_FILES['File']['tmp_name']);
               if($width > $max_width || $height > $max_height) {
                    $input_errors[] = "The image height/width is too big";
               }
           }
          
     } else {
          $input_errors[] = "That type of file cannot be uploaded";
     }
     
     if (count($input_errors) == 0) {
          if (move_uploaded_file($_FILES['File']['tmp_name'], $uploaddir.'/'.$_FILES['File']['name'])) {
           echo "Uploaded file Successfully <p />";
          } else {
         echo "Could not copy file to location <p />";
          }
     } else {
      echo "The following errors occured: <p />";
          echo "<ul>";
          for ($j=0; $j < count($input_errors); $j++) {
               echo "<li>" . $input_errors[$j] . "</li>";
      }
          echo "</ul>";
     }
}

// display form whatever the result i.e. if user wants to upload more than one file

echo "Upload a file to the server";
echo <<< FOO
     <form action="upload.php" method="post" enctype="multipart/form-data">
     <input type=file name="File" size="20"><br />
     <input type=submit name="Upload" value="Upload">
     </form>
FOO;

?>


hope this helps! sorry about the (still) dodgy spacing in the script - looked right at the time!
Last edited by gardolas : 31-Mar-2004 at 07:29. Reason: Dodgy spacing
  #5  
Old 31-Mar-2004, 08:46
PenguinJr PenguinJr is offline
New Member
 
Join Date: Feb 2004
Posts: 19
PenguinJr is on a distinguished road
Thanx for the help! i'll be sure to test that out =D
 
 

Recent GIDBlogLast Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:28.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.