Jump to content

Image save driving me nuts!


herghost

Recommended Posts

Hi all,

 

hope you can help me with this:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<?php
session_start();
include('include/database.php');
include('include/header.php');
include('include/auth.php');



$userid = $_SESSION['SESS_USERID'];
$albumno = $_SESSION['albumno'];

?>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />


<title>Welcome to fanjunky.com! - New Music - Bands- MP3 - Tickets - Tour Dates - The Latest Band =  

<?php $sql = "SELECT * FROM user WHERE userid = '$userid'";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
{
  		echo $row['bandname'];
	}
} 
?>
</title>

<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="default.css" rel="stylesheet" type="text/css" media="screen" />
</head>

<body>
<div id="page">
<div id="content">
	<div class="post greenbox">
		<div class="title">
			<h1>band discography - Album Cover</h1>
		</div>
<div class="entry">
    <p>Please upload the album cover</p>
    <p>



<?php
$query = "SELECT `albumname`, `userid`, `albumno` FROM `banddisco` WHERE userid='$userid'";
$result = mysql_query($query);

echo "<select name='albumname'>";
for($i=0; $i < mysql_num_rows($result); $i++) {

    $albumname = mysql_fetch_object($result);
    echo "<option value='". $albumname->userid ."'>". $albumname->albumname ."'>". $albumname->albumno ."</option>";

}
echo "</select>";  





//define a maxim size for the uploaded images in Kb
define ("MAX_SIZE","1024");

//This function reads the extension of the file. It is used to determine if the file is an image by checking the extension.
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}

//This variable is used as a flag. The value is initialized with 0 (meaning no error found) and it will be changed to 1 if an errro occures. If the error occures the file will not be uploaded.
$errors=0;
//checks if the form has been submitted
if(isset($_POST['Submit']))
{
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
//if it is not empty
if ($image)
{
//get the original name of the file from the clients machine
$filename = stripslashes($_FILES['image']['name']);
//get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
//if it is not a known extension, we will suppose it is an error and will not upload the file, otherwize we will do more tests
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
//print error message
echo '<h1>Unknown extension!</h1>';
$errors=1;
}
else
{
//get the size of the image in bytes
//$_FILES['image']['tmp_name'] is the temporary filename of the file in which the uploaded file was stored on the server
$size=filesize($_FILES['image']['tmp_name']);

//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*1024)
{
echo '<h1>You have exceeded the size limit!</h1>';
$errors=1;
}


$newname="users/$userid/" .$albumname->albumno;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<h1>Copy unsuccessfull!</h1>';
$errors=1;
}}}}

//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors)
{
header("location: ../member_home.php?cover=1 ");
      exit();
}

?>   
   
    <p>Upload Cover </p>
    <form name="newad" method="post" enctype="multipart/form-data" action="">
<table>
<tr><td><input type="file" name="image"></td></tr>
<tr><td><input name="Submit" type="submit" value="Upload image"></td></tr>
</table>
</form>

    
</p></div>
		<div class="btm">
			<div class="l">
				<div class="r">
					<p class="meta"> </p>
				</div>
			</div>
		</div>
	</div>
        <br/>
        <div class="two-columns">
	  <div class="columnA">
			<div class="title red">
				<h2>sponsers</h2>
			</div>
			<div class="content">

<script type="text/javascript">
google_ad_client = "pub-1087428711969548";

google_ad_slot = "3081294343";
google_ad_width = 250;
google_ad_height = 250;

</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>


			</div>
	  </div>
		<div class="columnB">
			<div class="title blue">
				<h2>Random Bands</h2>
			</div>
			<div class="content">
<?php 

$sql = "SELECT * FROM user ORDER BY RAND() LIMIT 10";
$result = mysql_query($sql ,$con);
while($myrow = mysql_fetch_array($result))
{
echo "<table width ='90%'>";
echo "<tr>";
echo "<td>";
echo  $myrow['bandname'];
echo "</td>";
echo "<td>";
echo  "<a href='newprofile.php?userid=";
echo $myrow['userid'];
echo "'>View</a>";
echo "</td>";
echo "</tr>";
echo "</table>";
}
?>
                </div>
		</div>
		<div class="btm"> </div>
	</div>
  </div>
<!-- end content -->
<!-- start sidebar -->
<div id="sidebar">
	<ul>
		<li>
      <h2>Sponsers</h2>
			<ul>
				<li><script type="text/javascript"><!--
google_ad_client = "pub-1087428711969548";
/* 250x250, created 4/14/09 */
google_ad_slot = "6665679490";
google_ad_width = 250;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></li>
			</ul>

		  

<h2>Sponsers</h2>

                <ul>
			<li><script type="text/javascript"><!--
google_ad_client = "pub-1087428711969548";
/* 250x250, created 4/14/09 */
google_ad_slot = "6665679490";
google_ad_width = 250;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></li>
</ul>
	</li>
        </ul>	
</div>

<!-- end sidebar -->
<!-- end sidebar -->
<!-- end sidebar -->
</div>
<!-- end page -->
<div style="clear: both;"> </div>
<?php

include('include/footer.php')
?>



</body>
</html>

 

basically its meant to pull the last entry into a database from a band uploading album details and then name and save a file of the albumno (auto_increment).

 

it basically works for the 1st band. It will for example, create a file called 31 with the correct image. If however the same band uploads another album, and the correct album is displayed in the drop down box, then when you save the file it just updates 31 instead of creating 32.

 

Any ideas?

 

 

Link to comment
https://forums.phpfreaks.com/topic/157297-image-save-driving-me-nuts/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.