Jump to content

Uploading image results in forbidden image??


mike12255

Recommended Posts

So im trying to upload an image (exaple - schoolworkanswers.com/kaon/imges/DOGGY.jpg) but it says the file is forbidden and i think this is whats stopping me from being able to display it. All the pictures in that folder that were not uploaded using my script are not forbidden and have no problems, any suggestions??:

 

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

//this returns the name of the image
$name = $_FILES['uploadfile']['name'];
//get the extension of the image
$ext = substr($name,-3);
//We will add some secruity here, make sure the extension is an image file extension
if($ext == "gif" || $ext == "jpg" || $ext == "png" || $ext == "peg"){

//The part the user selected to insert the image into
$area = $_POST['catagory'];

//get the descirption
$desc = $_POST['desc'];

//more security, make sure 'catagory' is actually a choice offered and not a mysql query (or something else entered)
if (!in_array($area, array("Sofas","Beds and Bunks","Dressers and Cabinets","Side Tables and Desks"))) {
header ("Location: index.php");
}
//set vars in here
$wantedname = $_POST['name'];

// This is the temporary file created by PHP
$uploadedfile = $_FILES['uploadfile']['tmp_name'];
//below changes the files name
if ($name != $wantedname){	
$name = $wantedname;
}

list($width,$height)=getimagesize($uploadedfile);
$newwidth = 100;
$newheight = 100;
//copy the file to were we want it now
//die($name);
//rename("$uploadedfile", "images/". $name .".". $ext);
$copied = copy($_FILES['image']['$uploadedfile'], $name .".". $ext);

if (!$copied) 
{
echo '<h1>Copy unsuccessfull!</h1>';
$errors=1;
}
$path = "images/" . $area . "/". $name .".". $ext;
//lets put it into the database
$uname = $name . "." . $ext;
$sql = "INSERT INTO tbl_product (pd_name,pd_path,pd_desc,cat_name) VALUES ('$uname','$path','$desc','$area')";

mysql_query($sql) or die (mysql_error());


}else{
header ("Location: index.php");	
}
?> 

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.