Jump to content

Option to add file or not


runnerjp

Recommended Posts

ok so i have my form and in it you can add a entry form via an upload.

 

The thing is its just an option so when i run my script

 

<?php
ini_set("display_errors", "1");
error_reporting(E_ALL);

if ((($_FILES["file"]["type"] == "application/msword"))
&& ($_FILES["file"]["size"] < 500000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    //echo "Type: " . $_FILES["file"]["type"] . "<br />";
   // echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
   // echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("entrys/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "entrys/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "entrys/" . $_FILES["file"]["type"];
      }
    }
  }
else
  {
  echo "Invalid file".$_FILES["file"]["name"];
  }

//print_r($_REQUEST['form']);





?>

 

to obvius im going to get  echo "Invalid file".$_FILES["file"]["name"];. Is there away to check if there is any information within the <div><label>File:</label> <input type="file" name="file" /></div> and if not dont run the file script? 

 

Just to add i want everything to work off this script so adding names ect so form looks like this

 

 <form  action="/include/addfixture.php" method="post" onsubmit="return AIM.submit(this, {'onStart' : startCallback, 'onComplete' : completeCallback})"enctype="multipart/form-data">
      <div><label>Name:</label> <input type="text" name="name" /></div>
      <div><label>File:</label> <input type="file" name="file" /></div>
      <div><label>Email:</label> <input type="text" name="email" /></div>
      <div><label>Event:</label> <input type="text" name="event" /></div>
      <div><label>Venue:</label> <input type="text" name="venue" /></div>

      <div><input type="submit" name="form"value="SUBMIT" /></div>

 

Link to comment
Share on other sites

I tried that with

 

if (isset($_FILES['file']))
{
if ((($_FILES["file"]["type"] == "application/msword"))
&& ($_FILES["file"]["size"] < 500000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    //echo "Type: " . $_FILES["file"]["type"] . "<br />";
   // echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
   // echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("entrys/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "entrys/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "entrys/" . $_FILES["file"]["type"];
      }
    }
  }
else
  {
  echo "Invalid file".$_FILES["file"]["name"];
  }
}

 

but i still get invalied file... wont it prosses it due to it being within the form even if it has nothing in it...i would have thought u had to see if it was blank and if so dont do it

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.