uploading files problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eektech909
Forum Commoner
Posts: 34
Joined: Fri Jun 09, 2006 3:59 pm

uploading files problem

Post by eektech909 »

I setup and admin section to upload photos.
It will upload the photoes correctly but will not display them.
I recieve an HTTP 403 Forbidden error on ONLY the newly uploaded files.
The images are valid and not corrupt.

Here is the code.

Plz help!

Code: Select all

<?php
include ("adminstuff.php");
$uploadmaincat = $_POST['maincategory'];
$uploadsubcat = $_POST['subcategory'];
$upfold = $_POST['subcategory'];

$uploaddir = '../Photos/' . $upfold . '/';
$thumbuploaddir = '../Thumbs/' . $upfold . '/';

$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
$thumbuploadfile = $thumbuploaddir . basename($_FILES['thumbfile']['name']);

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_FILES['userfile']['name'])) {
   echo "Your full size photo was successfully uploaded.<br /><br />";
} else {
   echo "Your full size photo upload failed. Please Try Again.";
   exit();
}

if (move_uploaded_file($_FILES['thumbfile']['tmp_name'], $thumbuploaddir . $_FILES['thumbfile']['name'])) {
   echo "Your thumbnail photo was successfully uploaded.<br /><br />";
} else {
   echo "Your thumbnail photo upload failed. Please Try Again.";
   exit();
}

   	$adminfilename = basename($_FILES['userfile']['name']);
	$adminfilename = explode(".", $adminfilename);
	$uploadfilename =  ($adminfilename[0]);
	
	$mainadminfilename = explode("=", $uploadmaincat);
	$mainuploadfilename =  ($mainadminfilename[1]);
	
mysql_connect("$host", "$username", "$password")or die("Cannot connect to server");
mysql_select_db("$admin_db_name")or die("Cannot connect to database");
	
$sql = "INSERT INTO Photos SET " .
	"Ph_Main_Cat='$mainuploadfilename', " .
	"Ph_Sub_Cat='$uploadsubcat', " .
	"Ph_File_Name='$uploadfilename'";

if (mysql_query($sql)) {
	} else {
	echo mysql_error();
	}
	
?>
Mohit_Prog
Forum Commoner
Posts: 26
Joined: Mon Apr 23, 2007 6:10 am

Post by Mohit_Prog »

Where you store your newly uploaded photos?
It may happen that path is an issue at the time of displaying.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The code posted allows a user to choose any path to store their files. Also, $uploadfile and $thumbuploadfile aren't being used where it counts: move_uploaded_file().
eektech909
Forum Commoner
Posts: 34
Joined: Fri Jun 09, 2006 3:59 pm

ARgh

Post by eektech909 »

I've tried about 5 different tutorials to upload a file.

All of them upload the file to the designated folder but when I try to view the image i get

The website declined to show this webpage
HTTP 403
Most likely causes:
This website requires you to log in.

This error (HTTP 403 Forbidden) means that Internet Explorer was able to connect to the website, but it does not have permission to view the webpage.


if I upload the image using and FTP, I can view the file fine.

Is it the settings for the website?
Post Reply