...

View Full Version : Problem with uploading



Serex
06-24-2005, 03:22 AM
$uploaddir = "includes/pages/demos"; // destination of demo
$allowed_ext = "gif, jpg, jpeg, bmp"; // file extension
$max_size = "10000000"; // size

// Check Entension
$extension = pathinfo($_FILES['txtScreenshot']['name']);
$extension = $extension[extension];
$allowed_paths = explode(", ", $allowed_ext);
for($i = 0; $i < count($allowed_paths); $i++) {
if ($allowed_paths[$i] == "$extension") {
$ok = "1";
}
}

// Check File Size
if ($ok == "1")
{
if($_FILES['txtScreenshot']['size'] > $max_size)
{
// size is too big
}

// The Upload Part
if(is_uploaded_file($_FILES['txtScreenshot']['tmp_name']))
{
move_uploaded_file($_FILES['txtScreenshot']['tmp_name'], $uploaddir . '/' . $steam_id . "." . $key . ".screenshot" . $extension);
}

// successfull
}
else
{
// error
}


Hey. I have the above code that i am trying to use to upload a screenshot from a demo. all the user needs to do is locate the screenshot on their pc and click upload. im just wondering if you can see any problems with it. i keep hitting the error at the end.

thanks

SeeIT Solutions
06-24-2005, 03:27 AM
add


break;

after this line


$ok = "1";

SeeIT Solutions
06-24-2005, 03:29 AM
better still... replace


for($i = 0; $i < count($allowed_paths); $i++) {
if ($allowed_paths[$i] == "$extension") {
$ok = "1";
}
}

with


if (in_array($extension,$allowed_paths)) {
$ok = "1";
} else {
$ok = "0";
}

Serex
06-24-2005, 04:09 AM
ok that didnt seam to make any difference to the end result. any other ideas?

SeeIT Solutions
06-24-2005, 06:20 AM
What is this line supposed to be doing?


$extension = $extension[extension];

replace


$extension = pathinfo($_FILES['txtScreenshot']['name']);
$extension = $extension[extension];

with


$extension = explode(".",$_FILES['txtScreenshot']['name']);
$extension = $extension[(count($extension) - 1)];

Serex
06-24-2005, 07:29 AM
thanks for that. however still not the problem. i have a feeling that it could be the dir im trying to upload too.

is there a way i can tell a file to upload a file to say

[ current file path ] / images

without having to link the whole

home/www/...../dev/.. ect

anshul
06-24-2005, 11:51 AM
What should we choose?
FORM based upload or by establishing a FTP connection.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum