View Full Version : Upload File script... Not working! Pleaz tell me wuts wrong!
Im trying to work on a very very simple upload file script... I have a page with tons of code, and I entered this piece of code, that takes care of uploads:
if (isset($_POST['upload_re'])){
copy("$_POST['url']", "$_POST[File_name]");
}
and this is the code for the page: Upload.php:
<?php
print("<center><h2>Upload</h2></center><br>\r\n");
print("<form method=\"POST\" action=\"files.php\" ENCTYPE=\"multipart/form-data\">\r\n");
print("File: <input type=\"File\" name=\"url\"><br>\r\n");
print("New Filename: <input type=\"TEXT\" name=\"File_name\"><br>\r\n");
print("<input type=\"Submit\" value=\"Upload!\">\r\n");
print("<input type=\"Hidden\" name=\"upload_re\" value=\"1\">\r\n");
print("</form>\r\n");
print("");
?>
My problem is, whenever I try to uplooad a file, it will say:
<b>Notice</b>: Undefined index: 'url' in <b>thefile</b> on line <b>3</b><br />
So, could anyone tell me what exactly I am doing wrong??? Thanks a bunch if you could!:)
whitty
05-21-2003, 06:31 AM
You don't use the $_POST array for file upload boxes you use $_FILE array
Read more about them here (http://www.php.net/manual/en/features.file-upload.php)
Okay, THanks!! Sorry I hadnt replied!! I was gonnnneee!:o
BTW, that still doesnt work.... This is what I did for the main file:
if (isset($_POST['upload_re'])){
copy($_FILE['url'], "$_POST[File_name]");
}
and this is what it tells me:
<b>Notice</b>: Undefined variable: _FILE in <b>C:\Program Files\Abyss Web Server\htdocs\files\index.php</b> on line <b>3</b><br />
Any help? Please?
Okay,I figured out something, the $_FILE needs to be $_FILES, but Im still having trouble!
<b>Warning</b>: copy(Array) [<a href='http://www.php.net/function.copy'>function.copy</a>]: failed to create stream: No such file or directory in <b>C:\Program Files\Abyss Web Server\htdocs\files\index.php</b> on line <b>3</b><br />
sleepingdanny
05-24-2003, 03:11 PM
This will do the job:
<input type="file" name="upload_re" value="<?=$upload_re?>">
if(is_uploaded_file($upload_re)){
copy($upload_re, $path . $upload_re_name);
}
That is the most basic code, but you can add the max size that a file can be uploaded in... and some more things. :thumbsup:
ReadMe.txt
05-24-2003, 05:16 PM
i ripped this straight out of the manual, it's a wonderful place to look when you are having trouble with some code:
<?php
// In PHP earlier then 4.1.0, $HTTP_POST_FILES should be used instead of $_FILES.
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
copy($_FILES['userfile']['tmp_name'], "/place/to/put/uploaded/file");
} else {
echo "Possible file upload attack. Filename: " . $_FILES['userfile']['name'];
}
/* ...or... */
move_uploaded_file($_FILES['userfile']['tmp_name'], "/place/to/put/uploaded/file");
?>
that should work fine for you with a form similar to this one:
<form enctype="multipart/form-data" action="_URL_" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1000">
Send this file: <input name="userfile" type="file">
<input type="submit" value="Send File">
</form>
just make sure you replace _URL_ with the location of the uploader script.
hmmm, that still doesnt work!:mad: I still got errors if I did exatly as u told me, so I altered it a bit to this:
if(isset($_POST['upload_re'])){
$path = "./uploads/";
copy($_FILES['upload_re'], $path . $_FILES['File_name']);
}
and the upload page as this:
<?php
print("<center><h2>Upload</h2></center><br>\r\n");
print("<form method=\"POST\" action=\"files.php\" ENCTYPE=\"multipart/form-data\">\r\n");
print("File: <input type=\"File\" name=\"upload_re\"><br>\r\n");
print("New Filename: <input type=\"TEXT\" name=\"File_name\"><br>\r\n");
print("<input type=\"Submit\" value=\"Upload!\">\r\n");
print("</form>\r\n");
print("");
?>
I dont really get an error this time... But it still wont upload anything...
ReadMe.txt
05-24-2003, 09:20 PM
you need to tell us the exact arror that you got, just copy it straight out of the browser when it comes up, also can you provide the exact script you were using that produced the error so we can see what might be up with it
That is the exact script that I used. It didnt show any error at all when I used it... Nothing at all, it just didnt upload it or anything...:confused:
ReadMe.txt
05-24-2003, 10:28 PM
ok, i'll give you a full script that i guarantee will work if you set up the variables and the permissions correctly
<?
if (!$_POST['submit']) {
?>
<form enctype="multipart/form-data" action="<?=$PHP_SELF?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1000">
Send this file: <input name="userfile" type="file">
<input type="submit" name="submit" value="Send File">
</form>
<?
} else {
// In PHP earlier then 4.1.0, $HTTP_POST_FILES should be used instead of $_FILES.
$path = "./uploads"
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
copy($_FILES['userfile']['tmp_name'], "/place/to/put/uploaded/file");
} else {
echo "Possible file upload attack. Filename: " . $_FILES['userfile']['name'];
}
}
?>
Okay, Ill try that! Ill tell u if it works!:o
Okay, it all works, except for, It wont upload ".bmp" 's or any other file besides ".jpg" and ".gif", and then, I get an error 200. Is that because the permissions are not set, and if not, how do I set them if I am using an Abyss web server?
BTW, could anyone visit http://www.l3vi.cjb.net/ and tell me what they get? Im working on getting a no-ip server and cant get it 2 work...
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.