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

17
  • You appear to be escaping the quote at the end Commented Sep 4, 2015 at 4:35
  • 1
    try "C:\\wamp\\www\\test\\img\\userPics\\"; or see the answer below. Commented Sep 4, 2015 at 4:42
  • 1
    did error reporting reveal anything for the other one, and using your existing syntax along with my suggestions? Commented Sep 4, 2015 at 4:43
  • 1
    @Fred-ii- Who would ever want to know they made an error?? It's not human nature to admit fallibility. Commented Sep 4, 2015 at 4:47
  • 1
    @Fred-ii- Ok for reals...later...stop editing your post... :D Commented Sep 4, 2015 at 5:00

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I am now off to lah lah land.
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

1 Comment

actually, they can use \ just as long as it's used as c:\\wamp\\www\\... if on a Windows server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.