Uploading files.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
davidtube
Forum Commoner
Posts: 79
Joined: Sun Mar 25, 2007 8:42 pm

Uploading files.

Post 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>";

User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Have you checked the manual: move_uploaded_file()?

Read the manual before asking such questions please.
davidtube
Forum Commoner
Posts: 79
Joined: Sun Mar 25, 2007 8:42 pm

Post by davidtube »

I've spent half the day looking at it but I can't understnad it.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Description
bool move_uploaded_file ( string $filename, string $destination )
The second paramater is the destination.
davidtube
Forum Commoner
Posts: 79
Joined: Sun Mar 25, 2007 8:42 pm

Post 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]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

You need to append the filename to the destination.

Code: Select all

$destination = "/2/videos/" . $_FILES['Submit']['name'];
davidtube
Forum Commoner
Posts: 79
Joined: Sun Mar 25, 2007 8:42 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The source doesn't exist.. hint hint hint.
davidtube
Forum Commoner
Posts: 79
Joined: Sun Mar 25, 2007 8:42 pm

Post by davidtube »

:oops: what?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
davidtube
Forum Commoner
Posts: 79
Joined: Sun Mar 25, 2007 8:42 pm

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