Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Help with this script

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Help with this script

Postby Socno » Mon Mar 04, 2013 3:16 pm

Hi. I am doing an tutorial on uploading files. However, when I try to make the code such as in the tutorial I get an error such as: Parse error: syntax error, unexpected $end in /home/a7309028/public_html/upload.php on line 39

here is the code:
Code: Select all
<?php

$name = $_FILES['file']['name'];
$extension = strtolower(substr($name, strpos($name, '.') +1));

$type = $_FILES['file']['type'];

$size = $_FILES['file']['size'];
$max_size = 2097152;

$tmp_name = $_FILES['file']['tmp_name'];

if (isset($name)) {
  if (!empty($name)) {
   
  if (($extension=='jpg'||$extension=='jpeg') && $type=='image/jpeg' && $size<=$max_size) {

    $location ='uploads/';
   
   if (move_uploaded_file($tmp_name, $location.$name)) {
     echo 'Uploaded!';
  }  else {
     echo 'There was an error';
  }

  }  else {
     echo 'File must be a jpg/jpeg and must be 2mb or less';
  }
 
  }  else {
     echo 'Please chooose a file.';
  }

?>

<form action="upload.php" method="POST" enctype="multipart/form-data">
      <input type="file" name="file"><br><br>
      <input type="submit" value="Submit">
      </form>
Socno
New php-forum User
New php-forum User
 
Posts: 1
Joined: Mon Mar 04, 2013 3:13 pm

Re: Help with this script

Postby simplypixie » Tue Mar 05, 2013 12:00 am

This error means you are missing a closing }. I found where it was but have combined your first 2 if statements anyway to save lines of code for you:
Code: Select all
if (isset($name) && !empty($name)) {

  if (($extension=='jpg'||$extension=='jpeg') && $type=='image/jpeg' && $size<=$max_size) {

    $location ='uploads/';

    if (move_uploaded_file($tmp_name, $location.$name)) {
      echo 'Uploaded!';
    }  else {
      echo 'There was an error';
    }

  } else {
  echo 'File must be a jpg/jpeg and must be 2mb or less';
  }

} else {
  echo 'Please chooose a file.';
}
User avatar
simplypixie
php-forum Active User
php-forum Active User
 
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron