PDA

View Full Version : help php!



jazzman121
September 1st, 2003, 01:27 PM
OK here is my multiple file uploading file script



&ltinput type="file" name="userfile[]" size="20" enctype="multipart/form-data">


i have 4 upload file inputs
in my page

and the php script im using is




$files = $HTTP_POST_FILES['userfile'];
if(!empty($userfile[0])) {
if(is_uploaded_file($userfile[0])){
move_uploaded_file($userfile[0], "/ft_files/1.jpg");
}
}


when i upload a file using the first input... i dont know why it doesnt upload the file.... could someone help me????? at php.net they said for multiple uploads use 'userfile' as an array


thanks

froZenX
September 1st, 2003, 01:38 PM
actually, its this:

$files = $HTTP_POST_FILES["userfile"];
if(!empty($userfile[0])) {
if(is_uploaded_file($userfile[0])){
move_uploaded_file($userfile[0], "/ft_files/1.jpg");
}
}

always use double quotes with arrays.

jazzman121
September 1st, 2003, 01:44 PM
tried it dint work :( ... the path is it relative to the folder the php file is in?

Syntax
September 1st, 2003, 01:57 PM
try




$files = $_FILES['userfile'];
if(!empty($files[0])) {
if(is_uploaded_file($files[0])){
move_uploaded_file($files[0], "/ft_files/1.jpg");

jazzman121
September 1st, 2003, 03:12 PM
nope that dint work either :( dont know wats wrong... i have even made sure the folder is chmod to write

jazzman121
September 1st, 2003, 03:18 PM
ok this is what i did

$files = $_FILES['userfile'];
echo $userfile[0];

and the result i got was

C:\\Documents and Settings\\user\\Desktop\\name.jpg

how do i remove the \\ and make it only \

?? thanks i think that might work

jazzman121
September 1st, 2003, 03:55 PM
ok i tried this out


$userfile = str_replace("\\", "\", $userfile);

now that worked but this is what happened to the result..

C:\\Documents and Settings\\user\\Desktop\\name.jpg

same result then i tried changing it to another charc to see if the str_replace works and it worked

i replaced the \ with + and it worked and i got this as the result

C:++Documents and Settings++user++Desktop++name.jpg

why is it doubling that char ? i dont understand

jazzman121
September 1st, 2003, 04:18 PM
ok i figured it out i just did this



$userfile = str_replace("\\\\\\\\", "\\\\", $userfile);


to get this

C:\Documents and Settings\user\Desktop\name.jpg

dint understand why thou ...

BUTT the


$files = $HTTP_POST_FILES["userfile"];
if(!empty($userfile[0])) {
if(is_uploaded_file($userfile[0])){
move_uploaded_file($userfile[0], "/ft_files/1.jpg");
}
}

still aint working :(

jazzman121
September 1st, 2003, 05:14 PM
I was thinking do i have to put

/var/www/html/

or something before the url?

Syntax
September 4th, 2003, 04:03 PM
try with copy()


if(@is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
copy($_FILES['userfile']['tmp_name'], "/ft_files/1.jpg");
}