sh0wtym3 Posted August 16, 2009 Share Posted August 16, 2009 I am working on an upload script, and I need the uploads to be uploaded to a different folder depending on which user is logged in. Here's my code: session_start(); $alias = $_SESSION['alias']; $filepath = getcwd()."/uploads/$alias/"; if(!file_exists($filepath)) { mkdir($filepath,0777); } chmod($filepath,0777); if(move_uploaded_file($_FILES['Filedata']['tmp_name'], $filepath.$_FILES['Filedata']['name'])){ chmod($filepath.$_FILES['Filedata']['name'], 0777); } But it does not work? However when I rewrite this line: $filepath = getcwd()."/uploads/$alias/"; to $filepath = getcwd()."/uploads/testuser/"; ... It works, and uploads the file to the directory "uploads/testuser". But I need to replace "testuser" with the value of $alias. Link to comment https://forums.phpfreaks.com/topic/170482-adding-variable-to-file-upload-path/ Share on other sites More sharing options...
asmith Posted August 16, 2009 Share Posted August 16, 2009 When does not work what does it say? get a echo of $_SESSION['alias'] to see if anything is stored there. Link to comment https://forums.phpfreaks.com/topic/170482-adding-variable-to-file-upload-path/#findComment-899279 Share on other sites More sharing options...
sh0wtym3 Posted August 16, 2009 Author Share Posted August 16, 2009 I cant see the error because I'm using a Flash/AJAX script so the user is not actually being redirected to the page the upload script is on. The file is uploaded and shows the user a progress bar/confirmation message without having to refresh the page. When I echo "$alias" and go to the page it shows the correct variable. So for some reason this: $filepath = getcwd()."/uploads/$alias/"; ... is not the correct syntax. The file is being uploaded to /uploads/ instead of /uploads/$alias/ for some reason Link to comment https://forums.phpfreaks.com/topic/170482-adding-variable-to-file-upload-path/#findComment-899287 Share on other sites More sharing options...
asmith Posted August 16, 2009 Share Posted August 16, 2009 After this : $filepath = getcwd()."/uploads/$alias/"; echo $filepath and check what the filepath is. Link to comment https://forums.phpfreaks.com/topic/170482-adding-variable-to-file-upload-path/#findComment-899288 Share on other sites More sharing options...
sh0wtym3 Posted August 16, 2009 Author Share Posted August 16, 2009 It echos out "/home1/mysite/public_html/members/cp/uploads/testuser/" The upload script is located in "/public_html/members/cp/" I need the script to create "/public_html/members/cp/uploads/testuser/" and upload the file there Link to comment https://forums.phpfreaks.com/topic/170482-adding-variable-to-file-upload-path/#findComment-899291 Share on other sites More sharing options...
asmith Posted August 16, 2009 Share Posted August 16, 2009 Then why you are using getcwd() ? where the main script is located? I don't know if the upload script itself is being included in another script? Wherever that main script is, set the path like : $filepath = "members/cp/uploads/$alias/"; Link to comment https://forums.phpfreaks.com/topic/170482-adding-variable-to-file-upload-path/#findComment-899304 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.