northernmics Posted May 21, 2007 Share Posted May 21, 2007 The following code pulls the variables from a flash movie. <?php $folder = $_POST['folder']; $path = "./files/".$folder."/"; //create the directory if doesn't exists (should have write permissons) if(!is_dir("./files/".$folder)) mkdir("./files/".$folder, 0755); //move the uploaded file move_uploaded_file($_FILES['Filedata']['tmp_name'], $path.$_FILES['Filedata']['name']); chmod($path.$_FILES['Filedata']['name'], 0777); ?> The $folder variable contains the username, the purpose is to create a user folder and move the uploaded image to it. This scriipt creates the proper folder " ./files/username/" but the image moves to " ./files/ " instead of the username folder. The code looks to be the same for both mkdir and move_uploaded_file, and Im confused why it is not working. Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/52386-solved-upload-script-not-working/ Share on other sites More sharing options...
Wildbug Posted May 21, 2007 Share Posted May 21, 2007 Have you printed the strings you're assembling to be sure they're correct? Are you getting any warnings/errors (do you have warnings turned on)? Is the file a valid, uploaded file? Quote Link to comment https://forums.phpfreaks.com/topic/52386-solved-upload-script-not-working/#findComment-258511 Share on other sites More sharing options...
northernmics Posted May 21, 2007 Author Share Posted May 21, 2007 There are no errors, and everything works properly but the image gets saved in the wrong folder. It does not see the $folder variable when it moves the file, but it does see it when it creates the folder. I am not to familuar with php, I only use it with my flash programs as a backend. Quote Link to comment https://forums.phpfreaks.com/topic/52386-solved-upload-script-not-working/#findComment-258519 Share on other sites More sharing options...
Wildbug Posted May 21, 2007 Share Posted May 21, 2007 Can you try this & post output? <?php error_reporting(E_ALL); // For debugging purposes. $path = './files/' . $_POST['folder'] .'/'; echo "Path: $path<br>\n"; if (!is_dir($path)) mkdir(rtrim($path,'/'), 0755); echo "New file: ", $path.$_FILES['Filedata']['name'], "<br>\n"; echo "File " . (is_uploaded_file($_FILES['Filedata']['tmp_name']) ? "is" : "is not") . " an uploaded file.<br>\n"; move_uploaded_file($_FILES['Filedata']['tmp_name'], $path.$_FILES['Filedata']['name']); chmod($path.$_FILES['Filedata']['name'], 0777); ?> Quote Link to comment https://forums.phpfreaks.com/topic/52386-solved-upload-script-not-working/#findComment-258528 Share on other sites More sharing options...
northernmics Posted May 21, 2007 Author Share Posted May 21, 2007 I am not sure how to test this properly because It uses variables that are only sent when the flash program sends them. If I run the php file I get errors that would occur without the variables. http://www.northernmics.com/php/again/upload.php Quote Link to comment https://forums.phpfreaks.com/topic/52386-solved-upload-script-not-working/#findComment-258550 Share on other sites More sharing options...
john010117 Posted May 21, 2007 Share Posted May 21, 2007 Then call it in your flash program. Quote Link to comment https://forums.phpfreaks.com/topic/52386-solved-upload-script-not-working/#findComment-258604 Share on other sites More sharing options...
northernmics Posted May 21, 2007 Author Share Posted May 21, 2007 called the path variable bck into flash and it came back the way it should ./files/username/ Quote Link to comment https://forums.phpfreaks.com/topic/52386-solved-upload-script-not-working/#findComment-258637 Share on other sites More sharing options...
Wildbug Posted May 22, 2007 Share Posted May 22, 2007 Hmm, not sure. Can you verify the permissions that are actually being set on the created dir and the moved file for me? Other than that, I might be out of ideas. Sorry. Quote Link to comment https://forums.phpfreaks.com/topic/52386-solved-upload-script-not-working/#findComment-258692 Share on other sites More sharing options...
northernmics Posted May 23, 2007 Author Share Posted May 23, 2007 Thanks for the attempt... I don't see how the ermissions would be any different from the folder /files/ because they are both created in the same script. I may not be an expert on php, but this code seems really simple.. but just does not work. The file/username/ folder is created in this script, but the move command only moves the uploaded file to the /file/ folder??? the move_uploaded_file script is the exact same as the mkdir??? Quote Link to comment https://forums.phpfreaks.com/topic/52386-solved-upload-script-not-working/#findComment-260215 Share on other sites More sharing options...
Wildbug Posted May 23, 2007 Share Posted May 23, 2007 But did you actually look to see the perms are set to what you thought they were set to? The actual result depends on the umask value. And even if it were different, maybe it wouldn't cause this error, but in leiu of any other idea, it's worth pursuing. Yes, it's a simple script, but it's not working and not giving you an error message, so you should check that each step is doing what it ought to be doing to find where things are going bad. Quote Link to comment https://forums.phpfreaks.com/topic/52386-solved-upload-script-not-working/#findComment-260284 Share on other sites More sharing options...
northernmics Posted May 24, 2007 Author Share Posted May 24, 2007 I checked the perm's and both the /files/ and /files/username/ folder are teh same at drwxrwxrwx. Quote Link to comment https://forums.phpfreaks.com/topic/52386-solved-upload-script-not-working/#findComment-260391 Share on other sites More sharing options...
northernmics Posted May 24, 2007 Author Share Posted May 24, 2007 <?php $folder = $_POST['folder']; $path = "./files/".$folder."/"; //create the directory if doesn't exists (should have write permissons) if(!is_dir("./files/".$folder)) mkdir("./files/".$folder, 0755); //move the uploaded file move_uploaded_file($_FILES['Filedata']['tmp_name'], "./files/".$folder."/".$_FILES['Filedata']['name']); chmod("./files/".$folder."/".$_FILES['Filedata']['name'], 0777); echo "&path="."$path"; ?> I exported the $path variable to my Flash file which represents the exact dir that the image is suppose to copy too. It returned ./files/username/ exactly where the file should go.... A Little frustratiing... Quote Link to comment https://forums.phpfreaks.com/topic/52386-solved-upload-script-not-working/#findComment-260399 Share on other sites More sharing options...
Wildbug Posted May 24, 2007 Share Posted May 24, 2007 Damn. Now I'm frustrated by your script. Quote Link to comment https://forums.phpfreaks.com/topic/52386-solved-upload-script-not-working/#findComment-260411 Share on other sites More sharing options...
northernmics Posted May 27, 2007 Author Share Posted May 27, 2007 I did not solve the problem, but I did make a solution and that was to make a seperate php script that is used after the uplaod function is finished. The second script renames the uploaded file to the username, creating the unique image file for each user. The drama though Thanks Quote Link to comment https://forums.phpfreaks.com/topic/52386-solved-upload-script-not-working/#findComment-262334 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.