Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

image upload error

images php coding issues or problems here.

Moderators: macek, egami, gesf

image upload error

Postby diasansley » Wed Oct 27, 2010 9:27 pm

i am gettin the foll error when i click submit
is_uploaded_file() expects parameter 1 to be string


th code:
<?php
if(!isset($_FILES['userfile'])) {
echo '<p>Please select a file</p>';
}
else
{
try {
upload();
echo '<p>Thank you for submitting</p>';
}
catch(Exception $e) {
echo $e->getMessage();
echo 'Sorry, could not upload file';
}
}
?>




<?php
print_r($_POST[name]);

function upload(){

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


if($_FILES['userfile']['size'] < $maxsize)
{

$imgData =addslashes (file_get_contents($_FILES['userfile']['tmp_name']));



$size = getimagesize($_FILES['userfile']['tmp_name']);



$username='root';
$password='admin';
mysql_connect("localhost", "$username", "$password") OR DIE (mysql_error());

// select the db
mysql_select_db ("$dbname") OR DIE ("Unable to select db".mysql_error());


$sql = "INSERT INTO testblob
( image_id , image_type ,image, image_size, image_name)
VALUES
('', '{$size['mime']}', '{$imgData}', '{$size[3]}', '{$_FILES['userfile']['name']}')";


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 />';
}
}
?>

<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="10000000" />
<input name="userfile[]" type="file" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
diasansley
New php-forum User
New php-forum User
 
Posts: 1
Joined: Wed Oct 27, 2010 9:10 pm

Re: image upload error

Postby parikhankit009 » Thu Nov 25, 2010 5:30 am

Yes you need to remove [] brackets from input tag name userfile[].
you need to place only name="userfile"

Let me know whether it works or not.
parikhankit009
New php-forum User
New php-forum User
 
Posts: 21
Joined: Tue Nov 16, 2010 5:11 am
Location: India

Re: image upload error

Postby meerakarthik » Wed Feb 09, 2011 9:00 pm

check this out
Code: Select all
<?php include("connect.php"); ?>
<?php

$fname = trim($_POST['fname']);
$lname = trim($_POST['lname']);
$gender = trim($_POST['gender']);
$phone = trim($_POST['txtPhone']);
$email = trim($_POST['mail']);
$location = trim($_POST['location']);
$zipcode = trim($_POST['zip']);
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {

     
      $tmpName  = $_FILES['image']['tmp_name']; 
       
      // Read the file
      $fp      = fopen($tmpName, 'r');
      $data = fread($fp, filesize($tmpName));
      $data = addslashes($data);
      fclose($fp);
     

      // Create the query and insert
      // into our database.
     /* $query = "INSERT INTO socialdb ";
      $query .= "(image) VALUES ('$data')";
      $results = mysql_query($query, $link);
      */
      // Print results
     
     
}
else {
 
}

   
 $query = "INSERT INTO socialdb(fname,lname,gender,dob,phone,email,location,zipcode,image)VALUES('$fname','$lname','$gender','$dob','$phone','$email','$location','$zipcode','$data')";
 $results=mysql_query($query,$link);
 if($result)
{
echo "Registered Successfully";
}
 
?>
meerakarthik
New php-forum User
New php-forum User
 
Posts: 5
Joined: Wed Feb 09, 2011 5:33 am


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.