/    Sign up×
Community /Pin to ProfileBookmark

Uploading image using php to host server

I’m trying to get photos to upload via an upload form to a photo folder on my host’s server but for some reason I keep getting the following error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/rox/public_html/random.inc on line 7

Here is my code

[CODE]
<?php

$randomiser = rand(0000, 99999);
$remove_these = array(‘ ‘,’`’,'”‘,”’,’\’,’/’);
$newname = str_replace($remove_these,”,$_FILES[‘pix’][‘name’]);
$newname = $randomiser.’-‘.$newname;
$upload_path = “$_SERVER[‘DOCUMENT_ROOT’] . ‘/photos/’$newname”;
move_uploaded_file($_FILES[‘pix’][‘tmp_name’], $upload_path);

$randomiser = rand(0000, 99999);
$remove_these = array(‘ ‘,’`’,'”‘,”’,’\’,’/’);
$newname2 = str_replace($remove_these,”,$_FILES[‘pix2’][‘name’]);
$newname2 = $randomiser.’-‘.$newname1;
$upload_path = “$_SERVER[‘DOCUMENT_ROOT’] . ‘/photos/’$newname2″;
move_uploaded_file($_FILES[‘pix2’][‘tmp_name’], $upload_path);

$randomiser = rand(0000, 99999);
$remove_these = array(‘ ‘,’`’,'”‘,”’,’\’,’/’);
$newname3 = str_replace($remove_these,”,$_FILES[‘pix3’][‘name’]);
$newname3 = $randomiser.’-‘.$newname3;
$upload_path = “$_SERVER[‘DOCUMENT_ROOT’] . ‘/photos/’$newname3”;
move_uploaded_file($_FILES[‘pix3’][‘tmp_name’], $upload_path);

?>
[/CODE]

I think there is something wrong with the $upload_path value but I can’t see where it is.

Can anyone help me? Thanks in advance

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@tirnaJul 02.2010 — I would just follow some Basic Debugging 101 principles.

If you haven't already done so, after
[CODE]

$upload_path = "$_SERVER['DOCUMENT_ROOT'] . '/photos/'$newname";
[/CODE]


maybe add

[CODE]
echo '$upload_path = '.$upload_path;
die();
[/CODE]


and check if $upload_path is correct in value and syntax.

If it isn't, then work back in your code to find and fix the problem.

If it is correct, then keep progressing down your code with echo and die() statements until you find the line causing the error.

If you have a debugger, then using it debugging will probably be quicker.
Copy linkTweet thisAlerts:
@criterion9Jul 02.2010 — Looking at this line:

$upload_path = "$_SERVER['DOCUMENT_ROOT'] . '/photos/'$newname";
[/quote]

I bet the problem is that you are not using the proper syntax for double quoted associative arrays.

The following are with proper syntax:
[code=php]
$upload_path = $_SERVER['DOCUMENT_ROOT'] .'/photos/'.$newname;
[/code]

[code=php]
$upload_path = "{$_SERVER['DOCUMENT_ROOT']}/photos/$newname";
[/code]

[code=php]
$upload_path = "$_SERVER[DOCUMENT_ROOT]/photos/$newname";
[/code]


http://www.php.net/manual/en/language.types.string.php (see variable parsing)

http://www.php.net/manual/en/language.variables.basics.php
×

Success!

Help @Hot_Chick035 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...