Advertisement

10.12.2008 at 04:50AM PDT, ID: 23807579
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.4

Tyring to get this sample file upload to work

Asked by Simon336697 in PHP Scripting Language

Hi guys hope you are all well and can help.
Guys Im working on trying to get this file upload php script that ive found to work.
It keeps bypassing the if statement and jumps right to the else as seen below.

File exceeds the Maximum File limit
Maximum File limit is
File Array is Array bytes


I have attached the fileupload script in the snippet and would love some help modifying it to work.
Im having issues trying to understand how to get the value for $maxsize and the:

if(is_uploaded_file($_FILES['userfile']['tmp_name'])) {

Any help greatly appreciated.

Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
======================================= fileupload.php:
 
 
<!-- ******************************************************
HTML FORM SECTION:
*********************************************************** -->
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html>
    <head><title>File Upload To Database</title></head>
    <body>
        <h3>Please Choose a File and click Submit</h3>
 
        <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
            <input name="userfile[]" type="file" />
            <input type="submit" value="Submit" />
        </form>
    </body>
</html>
 
 
<?php
/***********************************************************
UPLOAD SECTION:
***********************************************************/
 
// check if a file was submitted
if(!isset($_FILES['userfile'])) {
    echo '<p>Please select a file</p>';
}
else
    {
    try {
        upload();
        // give praise and thanks to the php gods
        echo '<p>Thank you for submitting</p>';
    }
    catch(Exception $e) {
        echo $e->getMessage();
        echo 'Sorry, could not upload file';
    }
}
 
?>
 
 
<?php
/***********************************************************
THE UPLOAD FUNCTION SECTION:
***********************************************************/
 
// the upload function
function upload(){
 
 
	if(is_uploaded_file($_FILES['userfile']['tmp_name'])) {
 
		// check the file is less than the maximum file size
		if($_FILES['userfile']['size'] < $maxsize) {
			
			// prepare the image for insertion
			$imgData =addslashes (file_get_contents($_FILES['userfile']['tmp_name']));
			// $imgData = addslashes($_FILES['userfile']);
			
			// get the image info..
			$size = getimagesize($_FILES['userfile']['tmp_name']);
		
			// put the image in the db...
		  	// database connection
		  	mysql_connect("localhost", "$username", "$password") OR DIE (mysql_error());
		
		 	// select the db
		  	mysql_select_db ("$dbname") OR DIE ("Unable to select db".mysql_error());
		
			// our sql query
			$sql = "INSERT INTO testblob
		        ( image_id , image_type ,image, image_size, image_name)
		        VALUES
		        ('', '{$size['mime']}', '{$imgData}', '{$size[3]}', '{$_FILES['userfile']['name']}')";
		
				// insert the image
				if(!mysql_query($sql)) {
				    echo 'Unable to upload file';
				}
		}
	}
	else {
		// if the file is not less than the maximum allowed, print an error
		echo
		'<div>File exceeds the Maximum File limit</div>
		<div>Maximum File limit is '.$maxsize.'</div>
		<div>File '.$_FILES['userfile']['name'].' is '.$_FILES['userfile']['size'].' bytes</div>
		<hr />';
	}
}
 
?>
 
Loading Advertisement...
 
[+][-]10.12.2008 at 05:02AM PDT, ID: 22697099

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP Scripting Language
Sign Up Now!
Solution Provided By: ali_kayahan
Participating Experts: 2
Solution Grade: A
 
 
[+][-]10.12.2008 at 05:04AM PDT, ID: 22697105

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]10.12.2008 at 05:11AM PDT, ID: 22697122

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.12.2008 at 05:19AM PDT, ID: 22697137

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.12.2008 at 05:24AM PDT, ID: 22697157

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.12.2008 at 05:25AM PDT, ID: 22697163

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.12.2008 at 05:27AM PDT, ID: 22697171

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.12.2008 at 05:28AM PDT, ID: 22697174

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.12.2008 at 05:29AM PDT, ID: 22697179

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.12.2008 at 05:34AM PDT, ID: 22697198

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.12.2008 at 05:38AM PDT, ID: 22697218

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.12.2008 at 05:48AM PDT, ID: 22697252

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.12.2008 at 06:32AM PDT, ID: 22697338

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.12.2008 at 06:37AM PDT, ID: 22697347

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.12.2008 at 06:41AM PDT, ID: 22697356

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.12.2008 at 07:08AM PDT, ID: 22697433

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628