Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Helo

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Helo

Postby Blazingsites » Tue Apr 29, 2014 6:17 am

Hi, Any help will be greatly appreciated, I've been changing stuff around and I don't get any results.
This script is to upload an image file into a folder. When I run it in localhost I get two errors.
The first is undefined index on line 14
that is
Code: Select all
if($_POST['file-included'] != 1)

The form shows nonetheless and when I try to upload a file I get error 403 Forbidden Access.
I run a number of other scripts in local host and never have I had this problem before, any help will be greatly appreciated.


Code: Select all
<html>
<body>

<?php

$upload_dir = "/uploadedimages/";

image_dir = "/images/";

if($_POST['file-included'] != 1)
{

 
$this_file = $_SERVER['PHP_SELF'];

?>

<form action="<?php=$this_file?>" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
<input type="hidden" name="file-included" value="1"
</form>

<?php
  exit;
}
// $_FILES An associative array of items uploaded to the current script via the POST method
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 300000))
  {
  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($upload_dir . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      $upload_dir . $_FILES["file"]["name"]);
      $file_location = $image_dir . $_FILES["file"]["name"];
      echo "Stored in: <a href='{$file_location}' target='new'>{$file_location}</a><br>";
      echo "<a href='".$this_file."'>Upload Another</a>";
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>

</body>
</html>
Blazingsites
New php-forum User
New php-forum User
 
Posts: 1
Joined: Tue Apr 29, 2014 6:11 am

Re: Helo

Postby seandisanti » Tue Apr 29, 2014 10:01 pm

You're evaluating the contents of a nonexistent index. Try like this instead:
Code: Select all
if(!empty($_POST['file-included']) && $_POST['file-included'] != 1)
 
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.