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
Bitweiser
Forum Newbie
Posts: 11 Joined: Sun Jul 30, 2006 9:27 am
Post
by Bitweiser » Mon Jul 31, 2006 10:58 am
Huy guys,
I've got a strange thing going on. I'm trying to upload a file to a directory called "uploads". When the code is installed on my first server, everything is working fine. On the second test server I've got an error. Both servers are windows NT/XP servers.
Here's the code:
Code: Select all
$target_path = "../../images/uploads/";
$uploadfile = $target_path . basename($_FILES['uploadedfile']['name']);
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $uploadfile))
echo "everything ok"
else echo "error" ;
This is the output of
print_r($_FILES); :
Code: Select all
Array
(
[uploadedfile] => Array
(
[name] => testfile.jpg
[type] => image/pjpeg
[b][tmp_name] => .\php16.tmp[/b]
[error] => 0
[size] => 20752
)
)
I'm guessing the problem lies in the temp file. Where the hell is ".\" coming from?
Anyone?
TIA
Last edited by
Bitweiser on Mon Jul 31, 2006 11:51 am, edited 1 time in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jul 31, 2006 11:01 am
your code uses uploadedfile, while the output shows uploadedfile1, typo?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Jul 31, 2006 11:06 am
Unlikely this is the original code, there's a syntax error.
Why not just copy&paste the real one?
What about the paths?
And error reporting?
Code: Select all
error_reporting(E_ALL);
ini_set('display_errors', true);
$target_path = "../../images/uploads/";
$uploadfile = $target_path . basename($_FILES['uploadedfile']['name']);
if (!is_dir($target_path)) {
echo '<div>Debug: ', $target_path, ' is not a directory', "<div />\n";
}
if (!is_writable($target_path)) {
echo '<div>Debug: ', $target_path, ' is not writable', "<div />\n";
}
if (!is_file($_FILES['uploadedfile']['tmp_name'])) {
echo '<div>Debug: ', $_FILES['uploadedfile']['tmp_name'], ' file not found', "<div />\n";
}
Bitweiser
Forum Newbie
Posts: 11 Joined: Sun Jul 30, 2006 9:27 am
Post
by Bitweiser » Mon Jul 31, 2006 11:51 am
feyd wrote: your code uses uploadedfile, while the output shows uploadedfile1, typo?
Yep typo...I've changed it..
Bitweiser
Forum Newbie
Posts: 11 Joined: Sun Jul 30, 2006 9:27 am
Post
by Bitweiser » Mon Jul 31, 2006 12:34 pm
volka wrote: What about the paths?
And error reporting?
Code: Select all
if (!is_file($_FILES['uploadedfile']['tmp_name'])) {
echo '<div>Debug: ', $_FILES['uploadedfile']['tmp_name'], ' file not found', "<div />\n";
}
This returns "Debug: .\php19.tmp file not found"
But I can't see why? The directory exists (proof is_dir) and it's writable (proof is_writable).
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Jul 31, 2006 12:41 pm
And is there a php19.tmp in this directory?
./ is very strange for $_FILES...tmp_name
Bitweiser
Forum Newbie
Posts: 11 Joined: Sun Jul 30, 2006 9:27 am
Post
by Bitweiser » Mon Jul 31, 2006 12:45 pm
volka wrote: And is there a php19.tmp in this directory?
./ is very strange for $_FILES...tmp_name
Well eh... no (I guess not) because php returns file not found.
Indeed ./ is strange but why is it there and what can I do about it.
Perhaps a php.ini config problem ? Or Apache ?
daedalus__
DevNet Resident
Posts: 1925 Joined: Thu Feb 09, 2006 4:52 pm
Post
by daedalus__ » Mon Jul 31, 2006 1:47 pm
yeah.. you should probably set that if it isn't i had trouble with that the other day