Page 1 of 1

Uploading files.

Posted: Mon Apr 16, 2007 3:17 pm
by davidtube
Hi. I need to change the loction that uploaded files save to here. I@m using apache and they're saving to C:\Program Files\xampp but I want them to save to C:\Program Files\xampp\htdocs\2\videos (but in a way that will still work when I upload the site to a webserver.

Thanks for any help in advance.

Code: Select all

$uploadfile =  $_FILES['Submit']['name'];

echo '<pre>';
if (move_uploaded_file($_FILES['Submit']['name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";


Posted: Mon Apr 16, 2007 3:32 pm
by Oren
Have you checked the manual: move_uploaded_file()?

Read the manual before asking such questions please.

Posted: Mon Apr 16, 2007 3:46 pm
by davidtube
I've spent half the day looking at it but I can't understnad it.

Posted: Mon Apr 16, 2007 3:48 pm
by John Cartwright
Description
bool move_uploaded_file ( string $filename, string $destination )
The second paramater is the destination.

Posted: Mon Apr 16, 2007 4:25 pm
by davidtube
Thanks.

Well I've tried this,

Code: Select all

$uploadfile =  $_FILES['Submit']['name'];

$destination = "/2/videos/";

echo '<pre>';
if (move_uploaded_file($_FILES['Submit']['name'], $destination)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";
And I'm getting this returned,
Possible file upload attack!
Here is some more debugging info:Array
(
[Submit] => Array
(
[name] => Adam_Nickey_-_Trance_Experience_012_Jennifer_Rene_Guestmix_(Afterhours.FM)-21-03-SBD-2007.torrent
[type] => application/x-bittorrent
[tmp_name] => C:\Program Files\xampp\tmp\phpB04.tmp
[error] => 0
[size] => 13973
)

)
And the file isn't appearing anywhere. Sorry I'm sure it's easy when you know what you're doing.[/syntax]

Posted: Mon Apr 16, 2007 4:37 pm
by John Cartwright
You need to append the filename to the destination.

Code: Select all

$destination = "/2/videos/" . $_FILES['Submit']['name'];

Posted: Mon Apr 16, 2007 4:46 pm
by davidtube
Thanks. I'm still getting the same problem though. Am I doing the slashes the right way round? I've tried it both ways and neither work.

Posted: Mon Apr 16, 2007 4:50 pm
by feyd
The source doesn't exist.. hint hint hint.

Posted: Mon Apr 16, 2007 5:19 pm
by davidtube
:oops: what?

Posted: Mon Apr 16, 2007 5:24 pm
by John Cartwright
what does

Code: Select all

var_dump(file_exists('/2/videos/'));
output? If it is false, then as feyd suggested the source directory does not exist.

Posted: Mon Apr 16, 2007 5:43 pm
by davidtube
Well done feyd and thanks Jcart for explaining it Jcart.

I've done this and it comes out with two trues now (it didn't before):

Code: Select all

<?php
var_dump(file_exists('\videos\\'));
var_dump(file_exists('/videos/'));
?>
I had to put the videos folder in C:\ but I want it in C:\Program Files\xampp\htdocs\2\. How do I do this so that it works when I upload it my off my local machine?