nickharambee Posted March 31, 2011 Share Posted March 31, 2011 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 Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted March 31, 2011 Share Posted March 31, 2011 Of course you have to make sure that the file that defines $targetFolder is included before this and that the echo is not in a function: <?php echo $targetFolder . $_SESSION["name"];?> Quote Link to comment Share on other sites More sharing options...
nickharambee Posted March 31, 2011 Author Share Posted March 31, 2011 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' Quote Link to comment Share on other sites More sharing options...
nickharambee Posted April 2, 2011 Author Share Posted April 2, 2011 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.