Jump to content



Welcome to AstaHost - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!

Toggle shoutbox Shoutbox Open the Shoutbox in a popup

@  yordan : (16 June 2013 - 05:41 PM) You're Welcome, Agyat!
@  agyat : (16 June 2013 - 07:38 AM) Thanks Yordan...
@  velma : (16 June 2013 - 12:06 AM) I Have Asked Opa To Check For A Backup.. He'll Let Me Know Soon :)
@  velma : (16 June 2013 - 12:05 AM) T_T It Seems That Someone Has Deleted That Topic Since I Found The Url Of The Topic But It Gives Me An Error
@  yordan : (15 June 2013 - 10:31 PM) @velma : It's A Tuto On How To Create A Login Program.
@  yordan : (15 June 2013 - 10:31 PM) Happy Birthday To Youuuuuu Agyat!
@  yordan : (15 June 2013 - 10:31 PM) Ba$
@  agyat : (15 June 2013 - 04:41 PM) :(
@  agyat : (15 June 2013 - 04:41 PM) Where The Hall I Were? 15Th Is Almost At End And No-One Wished Me "happy Birthday"!!!
@  velma : (14 June 2013 - 10:39 AM) Which Tutorial Is He Searching For?
@  velma : (14 June 2013 - 10:38 AM) Which Tutorial Is He Searching For?
@  yordan : (14 June 2013 - 07:47 AM) Ok, Have A Look Tomorrow.
@  yordan : (13 June 2013 - 03:19 PM) @velma, Can You Have A Look At Feelay's Problem? Seems That His Tutorial Is Not Searchable Today.
@  Feelay : (13 June 2013 - 08:11 AM) Oh, Haha
@  velma : (12 June 2013 - 05:39 PM) T_T Lately My Levels Of Procrastination..... **sigh**
@  velma : (12 June 2013 - 05:38 PM) I'll Do It Later
@  velma : (12 June 2013 - 05:38 PM) Procrastinators.. People Who Keep Saying "i'll Do This In A Bit"
@  Feelay : (12 June 2013 - 02:05 PM) Deal Punishments To What?
@  velma : (12 June 2013 - 01:27 PM) T_T We Should Deal Punishments To Procrastinators... Especially Me
@  Feelay : (12 June 2013 - 12:06 PM) As Well As Making It More Secure.

Photo
- - - - -

Installing An Image Uploader To My Site


7 replies to this topic

#1 caronthegerman

caronthegerman

    Newbie [ Level 2 ]

  • Members
  • 25 posts

Posted 15 August 2010 - 11:17 PM

Hey guys,

I'm having some trouble setting up a file uploader on my site. I used this website to make the uploader and did everything as I was told, as far as I know. I double checked my code and have no idea what I'm doing wrong.

When I try to upload a file I get an error message:
Parse error: syntax error, unexpected T_VARIABLE in /home/caronthegerman/loldmypants.com/pictures/uploader/upload.php on line 73

Here is uploadimage.html: (View it here.)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR...d"><html><head>    <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">  <meta name="google-site-verification" content="-XdND18efjz9LUFurJmW397G7-15WzTHnGlaxk8uGbw">  <title>Submit a Picture</title>      <meta content="Andrew Roberson, Blackwell Stith, Caron Schaller" name="author">    <meta content="Where Memes Go to Die" name="description"> </head><body style="background-image: url(http://www.goowik.co.../background.jpg);"><div style="text-align: center;"><script type="text/javascript"><!--google_ad_client = "pub-6677878668571681";/* Homepage Banner created Sat, Aug 7th 2010 */google_ad_slot = "0838308373";google_ad_width = 468;google_ad_height = 60;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script><script type="text/javascript"><!--google_ad_client = "pub-6677878668571681";/* Homepage Banner created Sat, Aug 7th 2010 */google_ad_slot = "2337475403";google_ad_width = 468;google_ad_height = 60;//--></script><script type="text/javascript"src="http://pagead2.googl.../div><br><br><a href="http://www.loldmypan...sp;&nbsp;&nbsp; <a href="http://www.loldmypan...sp;&nbsp;&nbsp; <a href="http://www.loldmypan...;&nbsp;&nbsp;<a href="/advertisestats.html">Advertise with us</a><big><br style="font-family: Desdemona; color: rgb(51, 102, 255); font-weight: bold;"></big><big><div style="text-align: center;"><big><big><span style="font-family: Desdemona; color: rgb(51, 102, 255); font-weight: bold;">L</span><big><span style="font-family: Desdemona; color: rgb(51, 102, 255); font-weight: bold;">L</span><big><span style="font-family: Desdemona; color: rgb(51, 102, 255); font-weight: bold;">L</span><big><span style="color: rgb(51, 102, 255); font-weight: bold; font-family: Desdemona;">LOLD</span><small><span style="color: rgb(51, 102, 255); font-weight: bold; font-family: Desdemona;">D</span><small><span style="color: rgb(51, 102, 255); font-weight: bold; font-family: Desdemona;">D</span><small><span style="font-family: Desdemona; color: rgb(51, 102, 255); font-weight: bold;">D&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; M</span><big><span style="font-family: Desdemona; color: rgb(51, 102, 255); font-weight: bold;">M</span><big><span style="font-family: Desdemona; color: rgb(51, 102, 255); font-weight: bold;">M</span><big><span style="color: rgb(51, 102, 255); font-weight: bold; font-family: Desdemona;">MY</span><small><span style="color: rgb(51, 102, 255); font-weight: bold; font-family: Desdemona;">Y</span><small><span style="color: rgb(51, 102, 255); font-weight: bold; font-family: Desdemona;">Y</span><small><span style="font-family: Desdemona; color: rgb(51, 102, 255); font-weight: bold;">Y&nbsp; &nbsp; &nbsp; P</span><big><span style="font-family: Desdemona; color: rgb(51, 102, 255); font-weight: bold;">P</span><big><span style="font-family: Desdemona; color: rgb(51, 102, 255); font-weight: bold;">P</span><big><span style="color: rgb(51, 102, 255); font-weight: bold; font-family: Desdemona;">PANTS</span><small style="font-family: Desdemona; color: rgb(51, 102, 255); font-weight: bold;">S<small>S<small><small>S</small></small></small></small><br></big><small style="color: white;"><small><span style="font-style: italic;">WhereMemes go to die.<br></span></small></small></big></big></big></small></small></small></big></big></big></small></small></small></big></big></big></big></big><small><small><br><br><br><font color="white"><div style="text-align: left"><big><big><b><u>Submitting a Picture: Part 2</u></b><br><br><!-- The data encoding type, enctype, MUST be specified as below --><form enctype="multipart/form-data" action="uploader/upload.php" method="POST">  <table align="left" cellpadding="5" cellspacing="5" border="0" width="100%" bgcolor=#FFFFFF>    <tr>      <td align="left" valign="top">        Select A File      </td>       <td align="left" valign="top">        <!-- MAX_FILE_SIZE (measured in bytes) must precede the file input field and its value         is the maximum filesize accepted by PHP. Fooling this setting on the browser side is         quite easy, so never rely on files with a greater size being blocked by this feature.         The PHP settings for maximum-size, however, cannot be fooled. This form element         should always be used as it saves users the trouble of waiting for a big file being         transferred only to find that it was too big and the transfer failed. -->        <input type="hidden" name="MAX_FILE_SIZE" value="2000000">         <!-- Name of input element determines name in $_FILES array.        uploaded_file is the reference assigned in the form. This will be needed to         tell the $_FILES array which file should be handled -->        <input name="uploaded_file" type="file">      </td>    </tr>     <tr>      <td align="left" valign="top">        &nbsp;      </td>       <td align="left" valign="top">        <input type="submit" value="Upload This File">      </td>    </tr>  </table></form><br><br><br><br></font><br><br></font></body></html>



Here is upload.php: (View it here.)
<?phpif ((($_FILES['uploaded_file']['type'] == 'image/gif')    ||     ($_FILES['uploaded_file']['type'] == 'image/png')    ||     ($_FILES['uploaded_file']['type'] == 'image/jpeg')   ||     ($_FILES['uploaded_file']['type'] == 'image/jpg')   ||     ($_FILES['uploaded_file']['type'] == 'image/pjpeg')) &&     ($_FILES['uploaded_file']['size'] < 2000000)) {if ($_FILES['uploaded_file']['error'] > 0) {  # The error code  associated with this file upload.  echo "Error: "     . $_FILES['uploaded_file']['error'] . "<br>";} else {  # The original name of the file on the client machine.  echo "Upload: "    . $_FILES['uploaded_file']['name'] . "<br>";   # The mime type of the file, if the browser provided this information.   # This mime type is however not checked on the PHP side and therefore it's value should  # should not be taken for granted.  echo "Type: "      . $_FILES['uploaded_file']['type'] . "<br>";   # The size, in bytes, of the uploaded file.  echo "Size: "      . ($_FILES['uploaded_file']['size'] / 1024) . " kB<br>";   # The temporary filename of the file in which the uploaded file was stored on the server.  echo "Stored in: " . $_FILES['uploaded_file']['tmp_name'] . "<br>";      # Where the file is going to be placed and thumbnail will be creatd; choose this judiciously    # These locations needs to have 'write' permissions for 'apache' (or the web-user)    $target_path = "useruploadstrue/";    $target_thumb_path = "useruploads/";     if(!is_writable($target_path)) {      die('Cannot be uploaded to the specified directory. Please change permission  to 777.');    }     if(!is_writable($target_thumb_path)) {      die('Thumbnail cannot be created. Please change permission  to 777.');    }   # This is the temporary file created by PHP.  $uploaded_file = $_FILES['uploaded_file']['tmp_name'];        # Create an image from the $uploaded_file so that it can be thumbnailed     $src = imagecreatefromjpeg($uploaded_file);     # Extract the original size of the uploaded image    list($width, $height)=getimagesize($uploaded_file);     # Let the thumbnail be 150 pixels in width, height adjusted based on original aspect ratio    $new_height   = 584;    $new_width  = ($width/$height)*$new_height;    $tmp         = imagecreatetruecolor($new_height, $new_width);     # The following line does the thumbnailing    imagecopyresampled($tmp, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height);     # Write the thumbnailed image to disk    # Check/modify this part for other image types    $filename = $target_thumb_path . $_FILES['uploaded_file']['name'];    imagejpeg($tmp, $filename, 100);     # PHP will clean up the temporary files after the request is completed    imagedestroy($src);    imagedestroy($tmp)     $target_path = $target_path . basename( $_FILES['uploaded_file']['name']);   if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $target_path)) {    echo "The file " .  basename( $_FILES['uploaded_file']['name']) . " has been uploaded";  } else{    echo "There was an error uploading the file, please try again!";  }}?>


Thanks for any helpful comments.

Edited by caronthegerman, 15 August 2010 - 11:20 PM.


#2 Feelay

Feelay

    Some random title

  • Members
  • 290 posts
  • Gender:Male
  • Location:Sweden

Posted 16 August 2010 - 01:05 AM

imagedestroy($tmp)
on line 69.

Try adding a ; at the end of that line, so that it looks like the following


imagedestroy($tmp);

In upload.php

Regards
/Nanashi

Edited by Feelay, 16 August 2010 - 01:11 AM.


#3 caronthegerman

caronthegerman

    Newbie [ Level 2 ]

  • Members
  • 25 posts

Posted 16 August 2010 - 08:28 AM

Ok I added the semicolon but now it has another error:
Parse error: syntax error, unexpected $end in /home/caronthegerman/loldmypants.com/pictures/uploader/upload.php on line 81

Line 81:
?>


I'm so confused D:

#4 Feelay

Feelay

    Some random title

  • Members
  • 290 posts
  • Gender:Male
  • Location:Sweden

Posted 16 August 2010 - 09:20 AM

On line 80, try adding another } so that it looks like the following:

}}

Regards
/Feelay

#5 caronthegerman

caronthegerman

    Newbie [ Level 2 ]

  • Members
  • 25 posts

Posted 16 August 2010 - 11:11 AM

Awesome, it worked! Thanks.

The only problem now is that the thumbnail part isn't working. But that's not important.

Instead, do you know how I could make an image rotator that rotates using multiple folders?
For example, it takes a random picture from 2 folders and shows it on the page and upon refresh a new picture is seen?
I found a few that do it with one folder, but I could not find one with 2 folders.

#6 Feelay

Feelay

    Some random title

  • Members
  • 290 posts
  • Gender:Male
  • Location:Sweden

Posted 16 August 2010 - 12:06 PM

I'm afraid it'd take too long time for me to explain and I'm kind of busy at the moment. Maybe if someone else could help you (If you start a new thread), because I have no idea when I'll be able to write you a tutorial =/

Regards
/Feelay

#7 8ennett

8ennett

    Premium Member

  • Members
  • 415 posts
  • Gender:Male
  • Location:UK
  • myCENTs:95.20

Posted 16 August 2010 - 01:24 PM

Something rather annoying about this post being stretched out like this, but never mind lol

Ok I'm going to write a function below for you so you can select a random image from a random folder each time the function is called.
What I have done is basically taken the coding example from here (so the credit really goes to that person) and just added a bit of extra functionality
too incorporate multiple folders.

function getRandomImage(){

// Change directories to your image directories, you can also add more if you wish eg. $randir[2] = 'images/randomdirectory3/'; just remember to add the trailing slash
$randir[0] = 'images/randomdirectory1/';
$randir[1] = 'images/randomdirectory2/';

$getrandir = array_rand($randir, 1);
$dir=opendir($randir[$getrandir[0]]);
$i=0;
while($imgfile = readdir($dir)){
if (($imgfile != ".") && ($imgfile != "..")){
$imgarray[$i] = $imgfile;
$i++;
}
}
closedir($dir);
$rand=rand(0,count($imgarray)-1);
if($rand >= 0){
return '<img src="'.$randir[$getrandir[0]].''.$imgarray[$rand].'" width="170" height="137">';
}
}

So now all you have to do is change the following lines:

$randir[0] = 'images/randomdirectory1/';
$randir[1] = 'images/randomdirectory2/';

to the directorys you want to pull a random image from and like I stated in the comments, you can add more directories if you wish.
So now you have changed your directories all you need to do is echo the function and it will display your image.

echo getRandomImage();

I haven't tested the modified code but looking over it there shouldn't be a problem, let me know if it works.

#8 caronthegerman

caronthegerman

    Newbie [ Level 2 ]

  • Members
  • 25 posts

Posted 16 August 2010 - 02:30 PM

Something rather annoying about this post being stretched out like this, but never mind lol

Ok I'm going to write a function below for you so you can select a random image from a random folder each time the function is called.
What I have done is basically taken the coding example from here (so the credit really goes to that person) and just added a bit of extra functionality
too incorporate multiple folders.

function getRandomImage(){

// Change directories to your image directories, you can also add more if you wish eg. $randir[2] = 'images/randomdirectory3/'; just remember to add the trailing slash
$randir[0] = 'images/randomdirectory1/';
$randir[1] = 'images/randomdirectory2/';

$getrandir = array_rand($randir, 1);
$dir=opendir($randir[$getrandir[0]]);
$i=0;
while($imgfile = readdir($dir)){
if (($imgfile != ".") && ($imgfile != "..")){
$imgarray[$i] = $imgfile;
$i++;
}
}
closedir($dir);
$rand=rand(0,count($imgarray)-1);
if($rand >= 0){
return '<img src="'.$randir[$getrandir[0]].''.$imgarray[$rand].'" width="170" height="137">';
}
}

So now all you have to do is change the following lines:

$randir[0] = 'images/randomdirectory1/';
$randir[1] = 'images/randomdirectory2/';

to the directorys you want to pull a random image from and like I stated in the comments, you can add more directories if you wish.
So now you have changed your directories all you need to do is echo the function and it will display your image.

echo getRandomImage();

I haven't tested the modified code but looking over it there shouldn't be a problem, let me know if it works.


I made a new topic since this really was getting annoying.
Here's the new topic.



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users