Jump to content

Archived

This topic is now archived and is closed to further replies.

nickharambee

string returned by variable not working like the same string entered manually

Recommended Posts

Hi,

 

I am trying to make some adjustments to uploadify.php which comes with the latest version of uploadify (3.0 beta), so that it works with a session variable that stores the login username and adds it to the path for uploads.  Here is uploadify.php as it currently looks:

 

<?php
session_name("MyLogin");
session_start();

$targetFolder = '/songs/' . $_SESSION['name']; // 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.';
}
}

echo $targetFolder;

?>

 

I added

echo $targetFolder;

at the bottom so that I could make sure that the string returned was correct, and it is, i.e. '/songs/nick'.  For some reason though, uploads are not going to the correct folder, i.e. the username folder, but instead are going to the parent folder 'songs'.  The folder for username exists, with correct permissions, and when I manually enter

$targetFolder = '/songs/nick';

all works fine.  Which strikes me as rather strange.  I have limited experience of using php, but wonder how if the correct string is returned by the session variable, the upload works differently than with the manually entered string.

 

Any help would be much appreciated.  It's the last issue with a website that was due to go live 2 days ago!

 

Thanks,

 

Nick

Share this post


Link to post
Share on other sites

Um srsly dude, if u dont know php, dont try using other ppls scripts. A script like uploadify.php really isnt that complicated. If i were u, id gt a book and start reading up on php. In that way, you wont even have to use other ppls scripts and the best part is...you woul actually understand what was going on!

 

Not trying to be mean but just giving u advice mainly becuz i used to be like that but after reading a small bOok i learned alt and have already moved on to javazcript

Share this post


Link to post
Share on other sites

×
×
  • 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.