I am having some problems with an upload script.
When testing on my home machine the code works intermittently.
sometimes it will say that the file is valid and uploaded. the next time I try I am told :
Possible file upload attack! Here's some debugging info:
Array
(
[userfile] => Array
(
[name] => boo.doc
[type] =>
[tmp_name] =>
[error] => 2
[size] => 0
)
)
The file exists as I have used a browse button to find it.
Below is my upload code
<?php
$uploaddir = 'gifs/';
$uploadfile = $uploaddir . $_FILES['userfile']['name'];
print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
print "File is valid, and was successfully uploaded. ";
// print "Here's some more debugging info:\n";
// print_r($_FILES);
} else {
print "Possible file upload attack! Here's some debugging info:\n";
print_r($_FILES);
}
print "</pre>";
?>
when i test on my 'server' i get the following message:
Warning: move_uploaded_file(gifs/house.gif): failed to open stream: Permission denied in /home/virtual/site8/fst/var/www/html/dbshoes/savefile.php on line 53
Can anyone tell me what I am doing wrong please
Is this something to do with the code or do I need to get something done to the folder?
Any help appreciated
upload problems
Moderator: General Moderators
-
nutstretch
- Forum Contributor
- Posts: 104
- Joined: Sun Jan 11, 2004 11:46 am
- Location: Leicester
upload problems
Last edited by nutstretch on Thu Mar 11, 2004 7:16 am, edited 1 time in total.
Code: Select all
<?php
if (!IsSet($_FILES['file'])) {
exit ("Type a file name in!");
}
else {
$name = $_FILES['file']['name'];
$stringname = $name;
$arrayname = explode(".",$stringname);
$extension = $arrayname[1];
$time = time();
$file = $time.".".$extension.".upl";
if(!move_uploaded_file($_FILES['file']['tmp_name'], 'upload/'.$file)) {
echo "The file <i>".$name."</i> cannot be uploaded.";
}
else {
echo "The file <i>".$name."</i> has been uploaded under this name: <i>".$file."</i>";
}
}
?>Joe
Last edited by Joe on Wed Sep 22, 2004 10:35 am, edited 1 time in total.
-
nutstretch
- Forum Contributor
- Posts: 104
- Joined: Sun Jan 11, 2004 11:46 am
- Location: Leicester
OK im sorry I should have explained that a bit more. The script I gave works as I tried it myself but there is a few simple steps you must take in order for it to function correctly. The steps are:
1.Create a directory in your web folder named 'upload'.
2.Create a file named upload.html (This is the upload form)
3.Create another file named upload.php (This is the upload script)
When a file is uploaded it will be put into the upload directory with a .upl extension. It works so give those steps a thoought and try again.
Regards
Joe
[/b]
1.Create a directory in your web folder named 'upload'.
2.Create a file named upload.html (This is the upload form)
3.Create another file named upload.php (This is the upload script)
When a file is uploaded it will be put into the upload directory with a .upl extension. It works so give those steps a thoought and try again.
Regards
Joe
[/b]