2

Im adding a string of a path to a variable, its pretty basic. Please see my image below:

The Problem

$target_dir = "C\wamp\www\test\img\userPics";

This above code works with no syntax errors BUT when I add a last backslash to the end of the string like so:

$target_dir = "C\wamp\www\test\img\userPics\"; 

I get all the syntax errors as you can see in image below.

Can anyone please explain to me why Im getting this error when adding a slash to the string as you can see on line 65?

enter image description here

Marilee
  • 1,598
  • 4
  • 22
  • 52

2 Answers2

2

Seeing you're wanting to run this on a Windows platform, you need to use an escaped method:

"C:\\wamp\\www\\test\\img\\userPics\\";

along with the escaped trailing slash.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
0

is should come as

$target_dir = "C/wamp/www/test/img/userPics/"; 

Change this \ to this /

But without pointing Full path use $_SERVER["DOCUMENT_ROOT"]

Read this as well

  1. Reference - What does this symbol mean in PHP?
  2. Backslash in PHP — what does it mean?
  3. Document Root PHP
Community
  • 1
  • 1
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85