Jump to content

Image Uploading form help plz


eziobeastmode

Recommended Posts

This code is giving me one warning and it is not functioning as it should . Files are below.i have following problems in this code and i dont know where am i doing wrong.i am confused:( .

1. Warning: implode(): Invalid arguments passed in \upload_new\upload.php on line 11

2. it doesnot check the empty fields and upload the image .if i select image only and press upload , it uploads image and dont check for empty fields.

3.i want to display the submitted code , but it doesnot displays.

 

 

upload.php

 

<?php 

//session 
session_start();
$errorPrint = '';
if(isset($_SESSION['form_upload']['errors']) && $_SESSION['form_upload']['errors'])
{
    $errorPrint = $_SESSION['form_upload']['errors'];
    unset($_SESSION['form_upload']['errors']);
}
echo implode("<br />",$errorPrint);
 ?>
 
 
 
<!DOCTYPE HTML> 
<html>
<head>
  <title>Upload Image form</title>
</head>
<body> 
 
<form action="formhandler.php" method="post" enctype="multipart/form-data">
 <br><br> 
Image Title:  <input type="text"    name="imagetitle"  ><br><br>
              <input type="hidden"  name="MAX_FILE_SIZE" value="2000000">
              <input type="file"    name="userfile"  id="userfile" ><br><br>
Choose Date:  <input type="date"    name="pickdate" > <br><br>
<input id="button_1" type="radio" name="option"  value="button1" /><label for="button_1" >Button 1</label>
<input id="button_2" type="radio" name="option"  value="button2" /><label for="button_2" >Button 2</label><br><br>
<select name="list1"> 
      <option value="">Select Options</option>
      <option value="option1">Option 1</option>
      <option value="option2">Option 2</option> 
      <option value="option3">Option 3</option>
</select>
<br><br>
 
<select name="list2"> 
      <option value="">Select Type</option>
      <option value="type1">Option 1</option>
      <option value="type2">Option 2</option> 
      <option value="type3">Option 3</option>
</select>
<br><br>
        <input name="upload" type="submit" class="box"  id="upload" value=" Upload " >
</form>
 
 
</body>
 
</html>
 
 
 
formhandler.php
 
 
<?php
//session 
session_start();
$_SESSION['form_upload']['errors'] = NULL;
 
 
 
$description=$fileSize=$filename=$date="";
 
if (isset($_POST['upload']))
 
 {
 
  if ($_FILES['userfile']['size'] > 0) 
  {
    
 
echo '<pre>'; // to get this work delete exit function at the  bottom
print_r($_POST); 
echo '</pre>';
 
 
$allowed_filetypes = array(
      '.jpg',
      '.jpeg',
      '.png',
      '.gif'
    );
 
 
    $max_filesize      = 1445760;
    $description       = $_POST['imagetitle'];
    $filename          = $_FILES['userfile']['name'];
    $ext               = substr($filename, strpos($filename, '.'), strlen($filename) - 1);
    if (!in_array($ext, $allowed_filetypes))
      die('The file you attempted to upload is not allowed.');
    
    if (filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die('The file you attempted to upload is too large.');
    
    $fileName = $_FILES['userfile']['name'];
    $tmpName  = $_FILES['userfile']['tmp_name'];
    $fileSize = $_FILES['userfile']['size'];
    $fileType = $_FILES['userfile']['type'];
    $date= $_POST['pickdate'];
 
    $fp       = fopen($tmpName, 'r');
    $content  = fread($fp, filesize($tmpName));
    $content  = addslashes($content);
    fclose($fp);
    if (!get_magic_quotes_gpc()) {
      $fileName = addslashes($fileName);
    } //!get_magic_quotes_gpc()
    
    include 'config.php';
    include 'opendb.php';
 
    $query = "INSERT INTO upload (name, size, type, content ,date,description ) " . "VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$date','$description')";
    mysql_query($query) or die('Error, query failed');
 
    include 'closedb.php';
    
    echo "<br>File $fileName uploaded<br>";
  
 
  }//isset($_POST['upload']) && $_FILES['userfile']['size'] > 0
    
   
  else {
    echo 'Please Upload an Image.';
  }
 
 
  } //isset($_POST['upload'])
 
 
 
 
 
 
echo "<h2>Your Input:</h2>";
echo "Title =".$description;
echo "<br>";
echo "Filename =".$filename;
echo "<br>";
echo "File size  =".$fileSize;
echo "<br>";
echo "Date =".$date;
 
 
 
if($errors) $_SESSION['form_upload']['errors'] = $errors;
header('Location: upload.php');
exit;
 
 
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.