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 Code:
<?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>
";
?>
Add this to the top of the script, just under the "<?php" part:
PHP Code:
print_r($_FILES);
Then go to your main page and upload a test image. When the page loads you will see a bunch of text looking something like this (variable names and number of files will be different, but generally it will look like this):
Add this to the top of the script, just under the "<?php" part:
PHP Code:
print_r($_FILES);
Then go to your main page and upload a test image. When the page loads you will see a bunch of text looking something like this (variable names and number of files will be different, but generally it will look like this):
This is not complete. Can you please double check your output and make sure that the entire string is there?
I've put it here. The PHP code has HTML around it but I don't know if that effects anything.
PHP Code:
<?php
print_r($_FILES);
$btnupload = $_POST['btnupload'];
$btnchoose = $_POST['btnchoose'];
$date = date("jS F Y, g:ia");
if ($_SESSION['LoginEmail']) {
if (isset($btnupload)) {
Then it comes out with: => /tmp/phpUNIUMu [error] => 0 [size] => 562204 ) )
Now, what we want to access will be under $_FILES['btnchoose']['type']
What you have in your code is $_FILES['picture']['type']
You need to change the word "picture" to "btnchoose" and this should work again. If you recently changed the name of your file input that's all it would take for this to have stopped working.
Now, what we want to access will be under $_FILES['btnchoose']['type']
What you have in your code is $_FILES['picture']['type']
You need to change the word "picture" to "btnchoose" and this should work again. If you recently changed the name of your file input that's all it would take for this to have stopped working.
Ahh, thanks. Yeh I tried cleaning the code up a bit thanks again!