Jump to content

Help needed adding echo to single line of script


nickharambee

Recommended Posts

Hi,

 

I am pretty much a new newbie when it comes to PHP, and have a problem that I need to solve, for a website that has to go live tomorrow.

 

Basically I have been using a javascript upload script called 'uploadify' which had an option for the upload folder which was added to the script in the form:

 

'folder'    : '/songs/<?php echo $_SESSION["name"];?>',

 

I added the php echo to return the username from a PHP login, so it gets added to the path to the upload folder (each user has their own subfolder for uploading to).

 

With the new version of the uploadify script, the folder option has been moved to a separate PHP file where it is now in the form:

 

$targetFolder = '/songs/';

 

I need to find a way of adding the username variable to this line.  I have tried using echo in various ways, and googled about, but it has stumped me, simple as it may be.

 

If anyone could let me know how I construct this line I'd be very grateful.  Time is of the essence, as they say...

 

Thanks,

 

Nick

Link to comment
Share on other sites

Thanks,

 

Here is the full script, as that should help to show what is included when:

 

<?php

$targetFolder = '/songs/'; // Relative to the root

if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') .'/'. $_FILES['Filedata']['name'];

// Validate the file type
$fileTypes = array('m4a','mp3','flac','ogg'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);

if (in_array($fileParts['extension'],$fileTypes)) {
	move_uploaded_file($tempFile,$targetFile);
	echo '1';
} else {
	echo 'Invalid file type.';
}
}
?>

 

The only other php file included with the script contains this:

 

<?php

if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/uploads/' . $_POST['filename'])) {
echo 1;
} else {
echo 0;
}
?>

 

I somehow need to include the '/songs/' part as well as that doesn't vary, only the subfolders in 'songs'

Link to comment
Share on other sites

I now have the session variable available to the uploadify.php page, by adding

session_name("MyLogin");

above

session_start();

Now when I add

echo $targetFolder;

it returns the correct path: '/songs/nick', but the uploads are still going to the parent directory 'songs'. When I manually enter

$targetFolder = '/songs/nick';

all works fine. Which seems rather weird. Does anyone have any ideas as to what might be going on?

 

Thanks,

 

Nick

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.