Jump to content

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


nickharambee

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

Link to comment
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

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.