Jump to content

Upload worries


mjahkoh

Recommended Posts

I got this upload class here but gives an error "The file extension is invalid, please try again! " even when the extension is ok.  Please i need your  help.

 

//begin testupload.php file

//==================

<?php

if($_POST['Submit']){

echo "<h1>sawa</h1>";

//$_FILES['upload']['name']

//echo "<h1>$_POST['Submit']</h1>";

include("class/upload.php");   

///start

$upload_class = new Upload_Files;

//$upload_class->temp_file_name = trim($_FILES['upload']['tmp_name']);

//$upload_class->file_name = trim(strtolower($_FILES['upload']['name']));

 

 

$upload_class->temp_file_name = trim($_FILES['tempfilename']);

$upload_class->file_name = trim(strtolower($_FILES[$_POST['file']]));

$upload_class->upload_dir = "uploads/";

$upload_class->upload_log_dir = "uploads/upload_logs/";

$upload_class->max_file_size = 5242880;

$upload_class->banned_array = array("");

$upload_class->ext_array = array(".zip",".rar",".ace",".tar","*.jpg");

 

 

$valid_ext = $upload_class->validate_extension(); 

$valid_size = $upload_class->validate_size();

$valid_user = $upload_class->validate_user();

$max_size = $upload_class->get_max_size();

$file_size = $upload_class->get_file_size();

$file_exists = $upload_class->existing_file();

 

if (!$valid_ext) {

$result = "The file extension is invalid, please try again!";

}

elseif (!$valid_size) {

$result = "The file size is invalid, please try again! The maximum file size is: $max_size and your file was: $file_size";

}

elseif (!$valid_user) {

$result = "You have been banned from uploading to this server.";

}

elseif ($file_exists) {

$result = "This file already exists on the server, please try again.";

} else {

$upload_file = $upload_class->upload_file_with_validation();

if (!$upload_file) {

$result = "Your file could not be uploaded!";

} else {

$result = "Your file has been successfully uploaded to the server.";

}

}

 

echo $_POST['file'] ;   

echo $result ;   

 

//end 

}

?> 

 

//==================

//end testupload.php file

 

The  upload class is  attached here

 

[attachment deleted by admin]

Link to comment
Share on other sites

ive decided to paste the entire code here. Please see why it doesnt upload yet i got the directory "uploads" and "uploads/logs" .

 

//Start Upload file

<?php     

if($_POST['Submit']){

include("class/upload.php");   

$upload_class = new Upload_Files;

$upload_class->temp_file_name = trim($_FILES['tempfilename']);

$upload_class->file_name = trim(strtolower($_FILES[$_POST['file']]));

$upload_class->upload_dir = "uploads/";

$upload_class->upload_log_dir = "uploads/upload_logs/";

$upload_class->max_file_size = 5242880;

$upload_class->banned_array = array("");

$upload_class->ext_array = array(".zip",".rar",".ace",".tar",".jpg");

$valid_ext = $upload_class->validate_extension(); 

$valid_size = $upload_class->validate_size();

$valid_user = $upload_class->validate_user();

$max_size = $upload_class->get_max_size();

$file_size = $upload_class->get_file_size();

$file_exists = $upload_class->existing_file();

if (!$valid_ext) {

$result = "The file extension is invalid, please try again!";

}

elseif (!$valid_size) {

$result = "The file size is invalid, please try again! The maximum file size is: $max_size and your file was: $file_size";

}

elseif (!$valid_user) {

$result = "You have been banned from uploading to this server.";

}

elseif ($file_exists) {

$result = "This file already exists on the server, please try again.";

} else {

$upload_file = $upload_class->upload_file_with_validation();

if (!$upload_file) {

$result = "Your file could not be uploaded!";

} else {

$result = "Your file has been successfully uploaded to the server.";

}

}

echo $result ;   

}

?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>uploadings </title>

</head>

<body>

<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">

    <input type="file" name="file" />

 

    <input type="submit" name="Submit" value="Submit" />

  </form>

</body>

</html>

 

//end upload  file

 

[attachment deleted by admin]

Link to comment
Share on other sites

Change these and it should work

 

$upload_class->temp_file_name = trim($_FILES['tempfilename']);
$upload_class->file_name = trim(strtolower($_FILES[$_POST['file']]));

 

to

 

$upload_class->temp_file_name = trim($_FILES['file']['tmp_name']);
$upload_class->file_name = trim(strtolower($_FILES['file']['name']));

Link to comment
Share on other sites

Use $_FILES like this

 

$_FILES['name of the file input in your form']

 

    * $_FILES["file"]["name"] - the name of the uploaded file

    * $_FILES["file"]["type"] - the type of the uploaded file

    * $_FILES["file"]["size"] - the size in bytes of the uploaded file

    * $_FILES["file"]["tmp_name"] - the name of the temporary copy of the file stored on the server

    * $_FILES["file"]["error"] - the error code resulting from the file upload

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.