So i try to set the session so when i try and upload the file it remebers
pi2, but when i upload the page it seems to loose the session.
if your browse down towards the middle of the page and look for
MY PROBELM then you will see the rest of the session code and wehere it
looses it at.
Thank you for any help you can provide me with.
Code: Select all
<?php
session_start();
$_SESSION["pic"] = $_GET['pic'];
$pic = $_SESSION["pic"];
$_SESSION["newpic"] = $pic;
print $_SESSION["newpic"];
include('includehtml.inc');
$name = $HTTP_COOKIE_VARS['user'];
$con = mysql_connect("localhost","pinehead","") or die(mysql_error());
$db = mysql_select_db("pinehead",$con) or die(mysql_error());
$sql = "SELECT * FROM users WHERE user='$name'";
$result = mysql_query($sql,$con);
$row = mysql_fetch_array($result);
$picname = $row['pic_url'];
$pictrue = $row['pic'];
mysql_close();
if ($_POST['updatepic']) {
$con = mysql_connect("localhost","pinehead","") or
die(mysql_error());
$db = mysql_select_db("pinehead",$con) or die(mysql_error());
$sql = "UPDATE users SET pic_text='$update' WHERE user='$name'";
mysql_query($sql,$con);
mysql_close();
}
if (isset($_FILES['file']['name'])) {
if ((($_FILES['file']['type'] == 'image/gif') ||
($_FILES['file']['type'] == 'image/pjpeg')) &&
(($_FILES['file']['size']
< 512000))) {
// Rename file using the date rename
// Get the extention then rename it and past the extention back onto the name
$ext = explode(".",$_FILES['file']['name']);
$mydate = date('Ymdhis');
$newname = "image$mydate.$ext[1]";
echo $newname;
if (file_exists('pics/' . $newname)) {
echo "File already exists!";
} else {
// Upload the file to the new location with the new name
move_uploaded_file($_FILES['file']['tmp_name'],
$_SERVER['DOCUMENT_ROOT'] . 'pics/' .
$newname);
echo "File uploaded sucessfully.";
// OTHER PART OF MY PROBLEM
// Here i'm trying to pull pic2 from the session created at the begginning of
//the page yet it wont - thats my probel please help if you can
session_start();;
$pic = $_SESSION["newpic"];
echo "</p>";
print $_SESSION["newpic"];
echo "</p>";
// end grab
$con = mysql_connect("localhost","pinehead","") or die(mysql_error());
$db = mysql_select_db("pinehead",$con) or die(mysql_error());
echo $pic;
// $sql = "UPDATE users SET ".$pic_id."='".$newname."', pic='true'
//WHERE user='".$name."'";
$sql = "UPDATE users SET $pic='$newname', pic='true' WHERE
user='$name'";
mysql_query($sql,$con);
mysql_close($con);
$oldpic = "/home/pinehead/www/pics/$picname";
if ($pictrue == "true") {
unlink($oldpic);
}
echo $newpicname;
echo $name;
}
} else {
echo "There was a problem uploading the file. Image restrictions were not
met.";
echo $_FILES['file']['error'] . "<br>";
echo $_FILES['file']['type'] . "<br>";
echo $_FILES['file']['size'];
}
} else {
echo "No file was submitted or there was an error. Err num: ";
echo $_FILES['file']['error'] . "<br>";
echo $_FILES['file']['type'] . "<br>";
echo $_FILES['file']['size'];
}
?>
<table border=0 cellpadding=0 cellspacing=0 width=97%>
<tr><td>Upload or change your picture below</td></tr>
</table>
<table cellpadding=0 cellspacing=0 width=97%>
<tr><td align=center>
<table border=0 cellpadding=0 cellspacing=0 width=80%>
<tr><td>
In order to add a picture to your profile or to update a current picture
on
your profile, click on the "Browse" button
below and select the picture file on your computer you wish to upload. Once you
have selected the file click on "Submit
Picture" and the picture will be added to your profile. You will be able to
see your current picture at the bottom of the
page.</p> </tr></td></table>
<form action=edit_pics.php method=post enctype=multipart/form-data>
<input type=file name=file><br>
<input type=submit value='Submit form'>
</form></tr></td></table>
<table border=0 cellpadding=0 cellspacing=0 height=3>
<tr><td> </td</tr>
</table>
<?PHP
$con = mysql_connect("localhost","pinehead","") or die(mysql_error());
$db = mysql_select_db("pinehead",$con) or die(mysql_error());
$sql = "SELECT * FROM users WHERE user='$name'";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
$picname = $row['pic_url'];
$pic = $row['pic'];
$pictext = $row['pic_text'];
mysql_close($con);
?>
<?php
if($_POST['delete']) {
$picer = "/home/pinehead/www/beta/pics/$picname";
unlink($picer);
echo $picname;
echo " has successfully been removed";
$default_pic = "nopic.jpg";
$con = mysql_connect("localhost","pinehead","") or die(mysql_error());
$db = mysql_select_db("pinehead",$con) or die(mysql_error());
$sql = "UPDATE users SET pic_url='$default_pic', pic='false'";
mysql_query($sql);
}
?>
<table border=0 cellpadding=0 cellspacing=0 width=97% align=center>
<tr><td>Your profile picture</td></tr>
</table>
<table border=0 cellpadding=0 cellspacing=0 width=97%>
<tr><td width=80%>
In order to update your picture you may upload a new one without deleting the
existing one.
If you would like to delete it alltogether click the delete link and your
picture will be removed.
</tr></td>
<tr><td align=center>
<?php
if ($pic == "false") {
echo "";
} else {
echo "<img src=http://lifeinkc.com/pics/$picname>";
echo "<br><form method=post action=edit_pics.php>
<input type=submit name='delete' value='Delete Picture'>
</form>";
}
?>
</tr></td>
</table>
<table border=0 cellpadding=0 cellspacing=0 width=97%>
<tr><td> </td></tr>
</table>
<?php
if($id == "main") {
echo "<table border=0 cellpadding=0 cellspacing=0 width=97%>
<tr><td>Piction text</td></tr>
</table>
<table border=0 cellpadding=0 cellspacing=0 width=97% align=center>
<tr><td align=center>
<table border=0 cellpadding=0 cellspacing=0 width=80% align=center>
<tr><td>
This is your picture text area, what you type below will show up directly
under your picture on your profile. You
are only allowed 155 charecters so choose your words wisely!</p>
<center><form action=edit_pics.php method=post>
<input type=text name='update' value=$pictext>
<input type=submit name='updatepic' value=Update>
</form>
</p> </tr></td></table>";
} else {
echo "";
}
include('includefooter.inc');
?>IF you have any questions please ask and if you have any solutions to my problem PLEASE help i pulled my hair out over this session problem all night for about 3 hours.
Thank you so much.
Anthony