Skiroid
09-01-2011, 06:22 PM
Hi, I'm working on my very first PHP/MySQL website and I'm quite excited about it: http://swiftsnap.skiroid.com/
However, one of my pages, front page, doesn't work as I'd like and am hoping one of you guys/gals could spot the fault within the code. I've checked it over numerous times but I just can't see what's going wrong.
Basically, I'm making an image uploading site and on the font page is a quick upload which checks whether the file selected is an image or not. If it is then it goes ahead and uploads it. Although, it's saying that images are not images and won't upload images.
I apologise if the code is messy or if there is unessential code but I am a noob when it comes to PHP.
<?php
$btnupload = $_POST['btnupload'];
$btnchoose = $_POST['btnchoose'];
$date = date("jS F Y, g:ia");
if ($_SESSION['LoginEmail']) {
if (isset($btnupload)) {
$name = $_FILES['picture']['name'];
$type = $_FILES['picture']['type'];
$tmpname = $_FILES['picture']['tmp_name'];
$ext = substr($name, strrpos($name, '.'));
if (strstr($type, "image")) {
$querysession = mysql_query("SELECT * FROM users WHERE LoginEmail='$sessionemail'");
while ($row = mysql_fetch_assoc($querysession)) {
$dbaccountid = $row['AccountID'];
}
$queryalbum = mysql_query("SELECT * FROM albums WHERE Name='Quick Upload' AND CreatedAccountID='$dbaccountid'");
while ($row = mysql_fetch_assoc($queryalbum)) {
$dbalbumid = $row['AlbumID'];
}
$charsetpictureid = '0123456789';
for ($i = 0; $i <= 10; $i++) {
$randpictureid = rand() % strlen($charsetpictureid);
$tmppictureid = substr($charsetpictureid, $randpictureid, 1);
$codepictureid .= $tmppictureid;
}
while ($numrows != 0) {
for ($i = 0; $i <= 10; $i++) {
$randpictureid = rand() % strlen($charsetpictureid);
$tmppictureid = substr($charsetpictureid, $randpictureid, 1);
$codepictureid .= $tmppictureid;
}
}
$charsetname = '0123456789';
for ($i = 0; $i <= 10; $i++) {
$randname = rand() % strlen($charsetname);
$tmpname = substr($charsetname, $randname, 1);
$codename .= $tmpname;
}
while ($numrows != 0) {
for ($i = 0; $i <= 10; $i++) {
$randname = rand() % strlen($charsetname);
$tmpname = substr($charsetname, $randname, 1);
$codename .= $tmpname;
}
}
mysql_query("INSERT INTO pictures VALUES ('$ccodepictureid','$dbalbumid','$codename','$name','$dbaccountid','$date')");
mkdir("album/$dbalbumid/");
move_uploaded_file($tmpname, "album/$dbalbumid/".$codename.$ext);
echo "
<div id='notification-yes'>
<div id='notification-yes-image'></div>
<h1>Your picture is ready to share!</h1>
<p>Your image has been uploaded to:<br /><a href='http://swiftsnap.skiroid.com/quickpic/$code$ext' target='_blank'>swiftsnap.skiroid.com/album/$dbalbumid/$codename$ext</a></p>
</div>
";
}
else
echo "
<div id='notification-no'>
<div id='notification-no-image'></div>
<h1>Unable to upload your file.</h1>
<p>You have either chosen a file which is not an image or you haven't chosen a file at all. You can only upload images to Swift Snap.</p>
</div>
";
}
else
echo "
<div id='notification-ok'>
<div id='notification-ok-image'></div>
<h1>Choose your image to upload.</h1>
<p>Swift Snap offers you a quick and easy service. All you have to do is choose an image you'd like to upload and you'll have the link to share it within seconds!</p>
</div>
";
}
else
if (isset($btnupload)) {
echo "
<div id='notification-no'>
<div id='notification-no-image'></div>
<h1>You need to be logged in.</h1>
<p>You are required to log in to Swift Snap to start uploading your pictures. Registration is free and should take no longer than a minute.</p>
</div>
";
}
else
echo "
<div id='notification-ok'>
<div id='notification-ok-image'></div>
<h1>Choose your image to upload.</h1>
<p>Swift Snap offers you a quick and easy service. All you have to do is choose an image you'd like to upload and you'll have the link to share it within seconds!</p>
</div>
";
?>
Thanks. :o
However, one of my pages, front page, doesn't work as I'd like and am hoping one of you guys/gals could spot the fault within the code. I've checked it over numerous times but I just can't see what's going wrong.
Basically, I'm making an image uploading site and on the font page is a quick upload which checks whether the file selected is an image or not. If it is then it goes ahead and uploads it. Although, it's saying that images are not images and won't upload images.
I apologise if the code is messy or if there is unessential code but I am a noob when it comes to PHP.
<?php
$btnupload = $_POST['btnupload'];
$btnchoose = $_POST['btnchoose'];
$date = date("jS F Y, g:ia");
if ($_SESSION['LoginEmail']) {
if (isset($btnupload)) {
$name = $_FILES['picture']['name'];
$type = $_FILES['picture']['type'];
$tmpname = $_FILES['picture']['tmp_name'];
$ext = substr($name, strrpos($name, '.'));
if (strstr($type, "image")) {
$querysession = mysql_query("SELECT * FROM users WHERE LoginEmail='$sessionemail'");
while ($row = mysql_fetch_assoc($querysession)) {
$dbaccountid = $row['AccountID'];
}
$queryalbum = mysql_query("SELECT * FROM albums WHERE Name='Quick Upload' AND CreatedAccountID='$dbaccountid'");
while ($row = mysql_fetch_assoc($queryalbum)) {
$dbalbumid = $row['AlbumID'];
}
$charsetpictureid = '0123456789';
for ($i = 0; $i <= 10; $i++) {
$randpictureid = rand() % strlen($charsetpictureid);
$tmppictureid = substr($charsetpictureid, $randpictureid, 1);
$codepictureid .= $tmppictureid;
}
while ($numrows != 0) {
for ($i = 0; $i <= 10; $i++) {
$randpictureid = rand() % strlen($charsetpictureid);
$tmppictureid = substr($charsetpictureid, $randpictureid, 1);
$codepictureid .= $tmppictureid;
}
}
$charsetname = '0123456789';
for ($i = 0; $i <= 10; $i++) {
$randname = rand() % strlen($charsetname);
$tmpname = substr($charsetname, $randname, 1);
$codename .= $tmpname;
}
while ($numrows != 0) {
for ($i = 0; $i <= 10; $i++) {
$randname = rand() % strlen($charsetname);
$tmpname = substr($charsetname, $randname, 1);
$codename .= $tmpname;
}
}
mysql_query("INSERT INTO pictures VALUES ('$ccodepictureid','$dbalbumid','$codename','$name','$dbaccountid','$date')");
mkdir("album/$dbalbumid/");
move_uploaded_file($tmpname, "album/$dbalbumid/".$codename.$ext);
echo "
<div id='notification-yes'>
<div id='notification-yes-image'></div>
<h1>Your picture is ready to share!</h1>
<p>Your image has been uploaded to:<br /><a href='http://swiftsnap.skiroid.com/quickpic/$code$ext' target='_blank'>swiftsnap.skiroid.com/album/$dbalbumid/$codename$ext</a></p>
</div>
";
}
else
echo "
<div id='notification-no'>
<div id='notification-no-image'></div>
<h1>Unable to upload your file.</h1>
<p>You have either chosen a file which is not an image or you haven't chosen a file at all. You can only upload images to Swift Snap.</p>
</div>
";
}
else
echo "
<div id='notification-ok'>
<div id='notification-ok-image'></div>
<h1>Choose your image to upload.</h1>
<p>Swift Snap offers you a quick and easy service. All you have to do is choose an image you'd like to upload and you'll have the link to share it within seconds!</p>
</div>
";
}
else
if (isset($btnupload)) {
echo "
<div id='notification-no'>
<div id='notification-no-image'></div>
<h1>You need to be logged in.</h1>
<p>You are required to log in to Swift Snap to start uploading your pictures. Registration is free and should take no longer than a minute.</p>
</div>
";
}
else
echo "
<div id='notification-ok'>
<div id='notification-ok-image'></div>
<h1>Choose your image to upload.</h1>
<p>Swift Snap offers you a quick and easy service. All you have to do is choose an image you'd like to upload and you'll have the link to share it within seconds!</p>
</div>
";
?>
Thanks. :o