Jump to content

Upload Forum Help!


Martinfin

Recommended Posts

This is what I basically got...

 

<?php // upload.php
echo <<<_END
<html><head><title>PHP Form Upload</title></head><body>
<form method='post' action='upload.php' enctype='multipart/form-data'>
Select File: <input type='file' name='filename' size='10' />
<input type='submit' value='Upload' />
</form>
_END;

if ($_FILES)
{
$name = $_FILES['filename']['name'];
move_uploaded_file($_FILES['filename']['tmp_name'], $name);
echo "Uploaded File '$name'<br /><img src='$name' />";
}

echo "</body></html>";
?>

 

What I am wanting to do with this is: Make the file go directly in my Folder called "Files" but instead it goes directly in the main htdocs folder.... Can anyone help me understand how to alter this to make it go to the files folder??

 

Thanks.

 

 

 

Link to comment
Share on other sites

add "/files/". to name.

like so

$name = "/files/".$_FILES['filename']['name'];

 

or wait do this instead:

   $name = $_FILES['filename']['name'];
   $folder = "/files/".$_FILES['filename']['name'];
   move_uploaded_file($_FILES['filename']['tmp_name'], $folder);

 

Link to comment
Share on other sites

add "/files/". to name.

like so

$name = "/files/".$_FILES['filename']['name'];

 

or wait do this instead:

   $name = $_FILES['filename']['name'];
   $folder = "/files/".$_FILES['filename']['name'];
   move_uploaded_file($_FILES['filename']['tmp_name'], $folder);

 

I appreciate your help me but when I added this it still goes to the same place like nothing was even changed.

 

Look to see if I messed it up if you don't mind...

<?php // upload.php
echo <<<_END
<html><head><title>PHP Form Upload</title></head><body>
<form method='post' action='upload.php' enctype='multipart/form-data'>
Select File: <input type='file' name='filename' size='10' />
<input type='submit' value='Upload' />
</form>
_END;

if ($_FILES)
{
        $name = $_FILES['filename']['name'];
        $folder = "/files/".$_FILES['filename']['name'];
        move_uploaded_file($_FILES['filename']['tmp_name'], $folder);
}

echo "</body></html>";
?>

 

Also I'm assuming you could try this out.. If so, Let me know if it worked for you and if it did.. maybe I just have no idea what I'm doing..:)

 

 

Link to comment
Share on other sites

Could find the EDIT button on this Page, I wanted to add, Here is what happens...

 

Warning: move_uploaded_file(/files/readme.txt) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\xampplite\htdocs\upload.php on line 14

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampplite\tmp\php2208.tmp' to '/files/readme.txt' in C:\xampplite\htdocs\upload.php on line 14

 

And yea, I'm using xampplite...:) I'm very new to this all but I catch on quick.

 

 

Link to comment
Share on other sites

$folder = "/files/".$_FILES['filename']['name'];

 

Using a forward sash at the start mens - start from ROOT of device. EG, C:. terefore your askingit to move the file to: C:/files/file.name

 

Use a ./ instead of a / eg:

$folder = "./files/".$_FILES['filename']['name'];

 

-cb-

Link to comment
Share on other sites

Where are you getting that from? Try uploading a file again, a small file, a .txt file or something.

 

If the code you posted earlier worked for you then this should too, your original post should be changed:

 

$name = $_FILES['filename']['name'];

to

$name = './files/'.$_FILES['filename']['name'];

 

-cb-

Link to comment
Share on other sites

Where are you getting that from? Try uploading a file again, a small file, a .txt file or something.

 

If the code you posted earlier worked for you then this should too, your original post should be changed:

 

$name = $_FILES['filename']['name'];

to

$name = './files/'.$_FILES['filename']['name'];

 

-cb-

 

Omg, Thank you so much... This works... I wasn't thinking that I didn't put in anything to let me know Upload completed. But your help was and still is ver much appreciated.

Thanks goes to ChemicalBliss and Lamez!!!

 

This topic can be closed but don't delete incase someone else has the same problem...:)

 

Take care man!

 

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.