Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP file upload intergated into my curently form (help please)
Old 10-08-2008, 07:55 PM PHP file upload intergated into my curently form (help please)
Novice Talker

Posts: 6
Trades: 0
hi i have been looking the whole day on how i can do file upload all the tutorials i get are not working for some reason or to complicated to intergate with my form...

i want 2 upload fields one for images and the other one for any type of files (large files)
if you can help... it would be great im so tired of searching on google...
if you give me a starting step would be great also im very new to php

here is were i want to have my upload form
Code:
<?php
include "inc/header.php";


  if(isset($_POST['submit']))
  {//begin of if($submit).
      
//global variables
      $title_en = $_POST['title_en'];
$title_ar = $_POST['title_ar'];
      $en = $_POST['en'];
      $ar = $_POST['ar'];
      $cat = $_POST['cat'];

              //check if (title) field is empty then print error message.
              if(!$title_en){  //this means If the title is really empty.
                     echo "Error: News title is a required field. Please fill it.";
                     exit(); //exit the script and don't do anything else.
              }// end of ifdtime

         //run the query which adds the data gathered from the form into the database
         $result = mysql_query("INSERT INTO contents (title_en, title_ar, dtime, en, ar, cat)
                       VALUES ('$title_en','$title_ar',NOW(),'$en','$ar','$cat')",$connect);
          //print success message.
          echo "<b>Thank you! data added Successfully!";
          echo "<meta http-equiv=Refresh content=2;url=index.php>";
  }//end of if($submit).


  // If the form has not been submitted, display it!
else
  {//begin of else

      ?>

      <h3>::Add News</h3> 
   <form method="post" action="<?php echo $_SERVER[PHP_SELF] ?>" enctype="multipart/form-data">  
  <table border="0" cellspacing="4" cellpadding="4">
  <tr>
    <td>Select Category:</td>
    <td colspan="2"><select name="cat"><?php
    
       $sql = 'SELECT DISTINCT `catname` from `categories`';
$result = @mysql_query($sql,$connect);
   while ($row = @mysql_fetch_assoc($result)) {
  echo '<option value="'.$row['id'].'">'.$row['catname'].'</option>';
}      ?>
    
    </td>
  </tr>
    <tr>
    <td>Title:</td>
    <td ><input name="title_en" size="40" maxlength="255"></td>
    <td><input name="title_ar" size="40" maxlength="255"></td>
  </tr>
    <tr>
      <td>Content:</td>
      <td><textarea name="eng"  rows="7" cols="30"></textarea></td>
      <td><textarea name="ar" rows="7" cols="30"></textarea></td>
    </tr>
    <tr>
      <td colspan="3" class="submit"><input type="submit" name="submit" value="Submit"></td>
    </tr>
</table>
      
</form>
     
      <?php
  }//end of else

 include "inc/footer.php";
  
?>

as for the view page i was thinking to have it in this way

echo file link only if a file have been uploaded
echo image only if an image have been uploaded
Darkwoods is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-09-2008, 12:58 AM Re: PHP file upload intergated into my curently form (help please)
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
OMG

"Handling file uploads" chapter of the native php manual covers the topic quite fine. You should add enctype="multipart/form-data" attribute to your form and then refer to $_FILES array in your script.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 10-14-2008, 07:13 AM Re: PHP file upload intergated into my curently form (help please)
Super Spam Talker

Latest Blog Post:
PSD Squirrel Launched
Posts: 932
Trades: 7
Code:
<html> 
<body>
  <form enctype="multipart/form-data" action="upload.php" method="post">
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
    Choose a file to upload: <input name="uploaded_file" type="file" />
    <input type="submit" value="Upload" />
  </form> 
</body> 
</html>
PHP Code:
<?php
//Сheck that we have a file
if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
  
//Check if the file is JPEG image and it's size is less than 350Kb
  
$filename basename($_FILES['uploaded_file']['name']);
  
$ext substr($filenamestrrpos($filename'.') + 1);
  if ((
$ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") && 
    (
$_FILES["uploaded_file"]["size"] < 350000)) {
    
//Determine the path to which we want to save this file
      
$newname dirname(__FILE__).'/upload/'.$filename;
      
//Check if the file with the same name is already exists on the server
      
if (!file_exists($newname)) {
        
//Attempt to move the uploaded file to it's new place
        
if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
           echo 
"It's done! The file has been saved as: ".$newname;
        } else {
           echo 
"Error: A problem occurred during file upload!";
        }
      } else {
         echo 
"Error: File ".$_FILES["uploaded_file"]["name"]." already exists";
      }
  } else {
     echo 
"Error: Only .jpg images under 350Kb are accepted for upload";
  }
} else {
 echo 
"Error: No file uploaded";
}
?>

.... http://www.webcheatsheet.com/PHP/file_upload.php
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Sir P is offline
Reply With Quote
View Public Profile Visit Sir P's homepage!
 
Old 10-14-2008, 07:32 AM Re: PHP file upload intergated into my curently form (help please)
Junior Talker

Posts: 3
Name: Jack Smith
Trades: 0
if you do print_r($_FILES) then you can view the element of the $_FILES array. This array contains all the uploaded file information.
__________________
Your window to latest technology:
Please login or register to view this content. Registration is FREE
jack239 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP file upload intergated into my curently form (help please)
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14264 seconds with 12 queries