Hello
I know how to upload a file with php. However, when I try upload a file to a different directory I can get it to work, but I can't get it to work another time.
It will work in the file below.
<?php
// ==============
// Configuration
// ==============
$uploaddir = "../product_images/";
// Where you want the files to upload to
//Important: Make sure this folders permissions (CHMOD) is 0777!
// ==============
// Upload Part
// ==============
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.$_FILES['file']['name']);
print "Your file has been uploaded successfully! Yay!";
}
else
{
print 'Something went wrong :(';
}
?>
It won't work in the file below.
<?php
// Include the Sessions options
require_once('inc/session_admin.inc.php');
$title = 'Game Added';
// Include the Doc type down to the head tag
require_once('inc/doctype-head.inc.php');
?>
<body bgcolor="#64b1ff">
<div align="center">
<?php
echo '<p>Hello <b>' .($_SESSION['username']) .'</b> <a href="logging_out.php">Logout</a></p>';
?>
<?php
// ==============
// Configuration
// ==============
$uploaddir = "../product_images/";
// Where you want the files to upload to
//Important: Make sure this folders permissions (CHMOD) is 0777!
// ==============
// Upload Part
// ==============
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.$_FILES['file']['name']);
print "Your file has been uploaded successfully! Yay!";
}
else
{
print "Something went wrong :(";
}
?>
<?php
/* Change db and connect values if using online */
$ProductName=$_POST['ProductName'];
$ProductPrice=$_POST['ProductPrice'];
$ProductPublisher=$_POST['ProductPublisher'];
$Blurb=$_POST['Blurb'];
// Include connecting to the database
require_once('inc/connect_to_product_db.inc.php');
if ($ProductName != '')
{
if ($ProductPrice != '')
{
if ($ProductPublisher != '')
{
if ($Blurb != '')
{
$result=mysql_query("INSERT INTO productinfo (ProductName, ProductPrice, ProductPublisher, Blurb) VALUES (
'$ProductName',
'$ProductPrice',
'$ProductPublisher' ,
'$Blurb')") or die("Insert Error: ".mysql_error());
mysql_close($link);
print "Game added!";
?>
<form method="post" action="add_a_new_game_form.php">
<input type="submit" value="Insert Another Record" />
</form>
<form method="post" action="display_games.php">
<input type="submit" value="Go to display table" />
</form>
<form method="post" action="index.php">
<input type="submit" value="Administrator Interface" />
</form>
<?php
}
else
{
?>
<table width="300" cellpadding="5" cellspacing="0" border="2">
<tr align="center" valign="top">
<td align="left" colspan="1" rowspan="1" bgcolor="#64b1ff">
<h3>Insert Game Information</h3>
<form method="post" action="add_a_new_game_script.php">
Game name: <input type='text' name='ProductName' size='30' value="<?php echo $ProductName ?>" /><br />
Game price:<br /> <input type='text' name='ProductPrice' size='30' value="<?php echo $ProductPrice ?>" /><br />
Game publisher: <input type='text' name='ProductPublisher' size='30' value="<?php echo $ProductPublisher ?>" /><br />
Blurb: <br /><textarea rows="10" cols="30" name="Blurb"></textarea><br />
You need to enter a Blurb about <?php echo $ProductName ?><br />
<br />
<input type='submit' value='Submit' /><input type='reset' />
</form>
<form method="post" action="index.php">
<input type="submit" value="Back to the Administrator Interface" />
</form>
</td>
</tr>
</table>
<?php
}
}
else
{
?>
<table width="300" cellpadding="5" cellspacing="0" border="2">
<tr align="center" valign="top">
<td align="left" colspan="1" rowspan="1" bgcolor="#64b1ff">
<h3>Insert Game Information</h3>
<form method="post" action="add_a_new_game_script.php">
Game name: <input type='text' name='ProductName' size='30' value="<?php echo $ProductName ?>" /><br />
Game price:<br /> <input type='text' name='ProductPrice' size='30' value="<?php echo $ProductPrice ?>" /><br />
Game publisher: <input type='text' name='ProductPublisher' size='30' /><br />
You need to enter the publisher of <?php echo $ProductName ?><br />
Blurb: <br /><textarea rows="10" cols="30" name="Blurb"><?php echo $Blurb ?></textarea><br />
<br />
<input type='submit' value='Submit' /><input type='reset' />
</form>
<form method="post" action="index.php">
<input type="submit" value="Back to the Administrator Interface" />
</form>
</td>
</tr>
</table>
<?php
}
}
else
{
?>
<table width="300" cellpadding="5" cellspacing="0" border="2">
<tr align="center" valign="top">
<td align="left" colspan="1" rowspan="1" bgcolor="#64b1ff">
<h3>Insert Game Information</h3>
<form method="post" action="add_a_new_game_script.php">
Game name: <input type='text' name='ProductName' size='30' value="<?php echo $ProductName ?>" /><br />
Game price:<br /> <input type='text' name='ProductPrice' size='30' value="<?php echo $ProductPrice ?>" /><br />
You need to enter the price of <?php echo $ProductName ?><br />
Game publisher: <input type='text' name='ProductPublisher' size='30' value="<?php echo $ProductPublisher ?>" /><br />
Blurb: <br /><textarea rows="10" cols="30" name="Blurb"><?php echo $Blurb ?></textarea><br />
<br />
<input type='submit' value='Submit' /><input type='reset' />
</form>
<form method="post" action="index.php">
<input type="submit" value="Back to the Administrator Interface" />
</form>
</td>
</tr>
</table>
<?php
}
}
else
{
?>
<table width="300" cellpadding="5" cellspacing="0" border="2">
<tr align="center" valign="top">
<td align="left" colspan="1" rowspan="1" bgcolor="#64b1ff">
<h3>Insert Game Information</h3>
<form method="post" action="add_a_new_game_script.php">
Game name: <input type='text' name='ProductName' size='30' /><br />
You need to enter the name of the game<br />
Game price:<br /> <input type='text' name='ProductPrice' size='30' value="<?php echo $ProductPrice ?>" /><br />
Game publisher: <input type='text' name='ProductPublisher' size='30' value="<?php echo $ProductPublisher ?>" /><br />
Blurb: <br /><textarea rows="10" cols="30" name="Blurb"><?php echo $Blurb ?></textarea><br />
<br />
<input type='submit' value='Submit' /><input type='reset' />
</form>
<form method="post" action="index.php">
<input type="submit" value="Back to the Administrator Interface" />
</form>
</td>
</tr>
</table>
<?php
}
?>
</div>
</body>
</html>
The folder product_images is the same folder in both instances.
Where am I going wrong?