Jump to content

[SOLVED] Upload script not working???


northernmics

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);

?>

Link to comment
Share on other sites

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???

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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...

 

Link to comment
Share on other sites

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

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.