...

View Full Version : Resolved Need help with basic PHP script



Skiroid
08-25-2011, 03:55 PM
Hi, I'm making a simple image upload site but I know very little PHP coding and was wondering whether any of you guys could help.

If you take a look at this link hopefully you'll be able to see what I'm trying to do closer, http://swiftsnap.skiroid.com/.

It all works well expect for I want the green or red notification box to replace the blue one instead of appearing underneath it.

Here is the code I've got at the moment. If you need to change the structure altogether please do.


<?php
echo "
<div id='notification-ok'>
<div id='notification-image'>
<img src='images/ok.png' width='100' height='100' />
</div>
<p id='notification-title'><strong>Pick your image to share.</strong></p>
<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>
";
if ($_POST['uploadbutton']) {
$name = $_FILES['picture']['name'];
$type = $_FILES['picture']['type'];
$tmpname = $_FILES['picture']['tmp_name'];
$charset = 'abcdefghijklmnopqrstuvwxyz0123456789';
$length = 15;
$ext = substr($name, strrpos($name, '.'));
if (strstr($type, "image")) {
for ($i = 0; $i <= $length; $i++) {
$rand = rand() % strlen($charset);
$tmp = substr($charset, $rand, 1);
$code .= $tmp;
}
while ($numrows != 0) {
for ($i = 0; $i <= $length; $i++) {
$rand = rand() % strlen($charset);
$tmp = substr($charset, $rand, 1);
$code .= $tmp;
}
}
move_uploaded_file($tmpname, "pictures/".$code.$ext);
echo "
<div id='notification-yes'>
<div id='notification-image'>
<img src='images/yes.png' width='100' height='100' />
</div>
<p id='notification-title'><strong>Your image is ready to share!</strong></p>
<p>Your image has been uploaded to:<br><a href='http://swiftsnap.skiroid.com/pictures/$code$ext' target='_blank'>swiftsnap.skiroid.com/pictures/$code$ext</a></p>
</div>
";
}
else
echo "
<div id='notification-no'>
<div id='notification-image'>
<img src='images/no.png' width='100' height='100' />
</div>
<p id='notification-title'><strong>Unable to upload your file.</strong></p>
<p>You have either chosen a file which is not an image or you havn't chosen a file at all. You can only upload images to Swift Snap.</p>
</div>
";
}
?>

I would appreciate any help. Thanks. :rolleyes:

Fou-Lu
08-25-2011, 04:10 PM
I won't follow links from work.
Is this what you are talking about?


echo "
<div id='notification-ok'>
<div id='notification-image'>
<img src='images/ok.png' width='100' height='100' />
</div>
<p id='notification-title'><strong>Pick your image to share.</strong></p>
<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>
";

?

If so, move that to the else of this branch: if ($_POST['uploadbutton']) (which should be if (isset($_POST['uploadbutton']))). Create the else and move that first print into it, then it will only show 1 of those three notification areas.

Skiroid
08-25-2011, 04:56 PM
I won't follow links from work.
Is this what you are talking about?


echo "
<div id='notification-ok'>
<div id='notification-image'>
<img src='images/ok.png' width='100' height='100' />
</div>
<p id='notification-title'><strong>Pick your image to share.</strong></p>
<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>
";

?

If so, move that to the else of this branch: if ($_POST['uploadbutton']) (which should be if (isset($_POST['uploadbutton']))). Create the else and move that first print into it, then it will only show 1 of those three notification areas.

Got it. Thanks! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum