0

I may be doing something horribly wrong, so that's why I want to ask this question.

{
    $pic = channelart.png;
    $pic_loc = $_FILES['pic']['tmp_name'];
    mkdir($userRow['user'], 0777, true);
    $folder="/.$userRow['user']";
    if(move_uploaded_file($pic_loc,$folder.$pic))
    {
        ?><script>alert('Successfully updated channel art.');</script><?php
    }
    else
    {
        ?><script>alert('Failed to update channel banner.');</script><?php
    }
}

I got this error:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /home/video10p/public_html/labs/au/index.php on line 7

Brandon White
  • 937
  • 9
  • 21
Whiz
  • 1
  • 1
  • 1
    You added you're code but forgot to add the error. Please add the error and read How to ask http://stackoverflow.com/help/how-to-ask And How to create a Minimal, Complete, and Verifiable example http://stackoverflow.com/help/mcve. – davejal Nov 22 '15 at 02:54

2 Answers2

0

Create folder before upload image :-

mkdir($userRow['user'], 0777, true);

Your code like this :-

{
    $pic = 'channelart.png';
    $pic_loc = $_FILES['pic']['tmp_name'];
    mkdir(trim($userRow['user']), 0777, true);
    $folder="/.trim($userRow['user'])";
    if(move_uploaded_file($pic_loc,$folder.$pic))
    {
        ?><script>alert('Successfully updated channel art.');</script><?php
    }
    else
    {
        ?><script>alert('Failed to update channel banner.');</script><?php
    }
}
Abhishek Sharma
  • 6,523
  • 1
  • 12
  • 20
  • Unfortunately, It still didn't work. It returned the error: "Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /home/video10p/public_html/labs/au/index.php on line 7" – Whiz Nov 22 '15 at 03:05
  • $pic = "channelart.png"; change this line – Abhishek Sharma Nov 22 '15 at 03:10
0

Change this $pic = channelart.png; to this $pic = "channelart.png";

You are getting the error because PHP is expecting a String, Variable or statement. The T_ENCAPSED_AND_WHITESPACE token picked up on this line tells us that the parser came upon another assignment, when it was expecting a String, Variable or Numeric.

PHP Tokens are extremely useful to debugging and I would strongly advise taking a look at the page linked above.

This should solve your posted error above.

Brandon White
  • 937
  • 9
  • 21