Page 1 of 1

File upload

Posted: Sun Jan 06, 2008 10:26 pm
by shruti0324
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello every one,below is the code which i wrote to upload the files to the folder and get back from it.I created a folder called upload which can store the uploaded files.After i upload the files i get the msg successfully uploaded but it wont get stored in the upload folder to get back the file.Plese let me know what is wrong in the code and how can i store it in the upload folder or any other folder.

Code: Select all

<?php

$uploaddir= "upload/";
// Where you want the files to upload to
//Important: Make sure this folders permissions is 0777!
$allowed_ext= "jpg, gif, png, pdf, html, doc";
// These are the allowed extensions of the files that are uploaded
$max_size= "750000";
// 750000 is the same as 7500kb
$max_height= "10000";
// This is in pixels - Leave this field empty if you don't want to upload images
$max_width= "10000";
// This is in pixels - Leave this field empty if you don't want to upload images

// Check Extension
$extension= pathinfo($_FILES['file']['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['file']['size'] > $max_size)
{
print "File size is too big!";
exit;
}

// Check Height & Width
if ($max_width && $max_height) {
list($width, $height, $type, $w) = getimagesize($_FILES['file']['tmp_name']);
if($width > $max_width || $height > $max_height)
{
print "File height and/or width are too big!";
exit;
}
}
// The Upload Part
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'. $_FILES['file']['name']);
}
print "Your file has been uploaded successfully! Yay!";
} else {
print "Incorrect file extension!";
}
?>
<form action="upload.php" method="post" ENCTYPE="multipart/form-data">
File: <input type="file" name="file" size="30"> <input type="submit" value="Upload!">
</form>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sun Jan 06, 2008 10:59 pm
by devendra-m
Did you check write permission for the folder upload

File upload

Posted: Mon Jan 07, 2008 7:58 am
by shruti0324
Yes,i have given all the permission to the folder.

Posted: Mon Jan 07, 2008 10:35 am
by markusn00b
I can't see anything wrong with it...

even when i tested that code on my pc it worked just fine.. a little sloppy though.

Posted: Tue Jan 08, 2008 3:28 pm
by superdezign
If the code works, then it's likely a problem of permissions. Sometimes, you need to give all permissions to the folder PHP will be uploading to as well as the folder that the upload folder is in. If you want to avoid the complications, actually build the folder from within PHP so that PHP already has the ownership permissions.