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

I cant Upload image file in my website : PHP Error

images php coding issues or problems here.

Moderators: macek, egami, gesf

I cant Upload image file in my website : PHP Error

Postby kshabeer997 » Fri Sep 24, 2010 9:42 pm

when i upload the error will show
"Warning: copy() [function.copy]: Filename cannot be empty in F:\xampp\htdocs\web\cicsbed\admin\addfac… on line 48"

the php code is given below :

Code: Select all
<?php
    session_start();
   
    if(!isset($_SESSION['logged']))
    {
        header("location:index.php");
    }
   
    $info = "";
   
    if(isset($_GET['id']))
    {
       
        require("connection.php");
       
        mysql_query("delete from photos where id='$_GET[id]'");
       
    }
   
    if(isset($_POST['Submit']))
    {       
        $size = $HTTP_POST_FILES["uploadfile"]["size"];
        if($size < 2000000)
        {
            if ($HTTP_POST_FILES["file"]["error"] > 0)
            {
                $info = "Invalid File.";
            }
            else
            {
                require("connection.php");
               
                $qry = mysql_query("select max(id) as maxid from photos");
               
                $rs = mysql_fetch_assoc($qry);
       
                $maxid = $rs['maxid'] + 1;
               
                $category = $_POST['category'];
               
                $ph_order = $_POST['ph_order'];
               
                if($_POST['Submit']=="Update")
                {
                    $maxid = $_REQUEST['eid'];
                }
               
                copy($HTTP_POST_FILES["images"]["tmp_name"], $_SERVER['DOCUMENT_ROOT']."upload/" . $maxid . $HTTP_POST_FILES["uploadfile"]["name"]);
               


                $fname_thumb = $maxid . $HTTP_POST_FILES["uploadfile"]["name"];

                $fname = $fname_thumb;
               
                $caption = $_POST['caption'];
                $names = $_POST['names'];
                $quali = $_POST['quali'];
                $exp = $_POST['exp'];
                $dob = $_POST['dob'];
                       
                if($_POST['Submit']=="Submit")
                {         
                    mysql_query("insert into photos(id, category, ph_order, photo_thumb, photo, caption, names, qualification, exper, dob) values($maxid, $category, '$ph_order', '$fname_thumb', '$fname', '$caption', '$names', '$quali', '$exp', '$dob' )");
                   
                    $info = "Uploaded Successfully.";
                }
                else
                {
                    $qry = mysql_query("select photo from photos where id='$_REQUEST[eid]'");
               
                    $rs = mysql_fetch_assoc($qry);
                   
                    unlink($_SERVER['DOCUMENT_ROOT']."upload/" . $rs['photo']);
               
                    mysql_query("update photos set category=$category, ph_order='$ph_order', photo_thumb='$fname_thumb', photo='$fname', caption='$caption', names='$names', qualification='$quali', exper='$exp',  dob='$dob' where id='$_REQUEST[eid]'");
                   
                    $info = "Updated Successfully.";
                }           
            }
        }
    }
?>
kshabeer997
New php-forum User
New php-forum User
 
Posts: 2
Joined: Fri Sep 24, 2010 9:33 pm

Re: I cant Upload image file in my website : PHP Error

Postby macek » Sun Sep 26, 2010 3:59 am

Copy is not function for handling uploaded files!

http://php.net/manual/en/function.move- ... d-file.php

And second problem could be in permissions :)
User avatar
macek
php-forum Active User
php-forum Active User
 
Posts: 277
Joined: Wed Aug 25, 2010 10:42 am

Re: I cant Upload image file in my website : PHP Error

Postby FR33K » Wed Oct 13, 2010 11:38 pm

"COPY" is not a function in PHP !!! u can use

Code: Select all
move_uploaded_file($_FILES["XXX"]["tmp_name"], $_SERVER['DOCUMENT_ROOT']."upload/" . $maxid . $_FILES["XXX"]["name"]);


this shooed work !!!!
replace "xxx" with the name from ur INPUT
FR33K
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Oct 13, 2010 10:59 pm

Re: I cant Upload image file in my website : PHP Error

Postby macek » Fri Oct 15, 2010 3:04 am

COPY is PHP function!!! http://php.net/manual/en/function.copy.php

But it is not for handling uploaded files :)
User avatar
macek
php-forum Active User
php-forum Active User
 
Posts: 277
Joined: Wed Aug 25, 2010 10:42 am

Re: I cant Upload image file in my website : PHP Error

Postby webinfopedia » Fri Jun 10, 2011 4:17 am

Hi..
Read my image uploading article below...
http://www.webinfopedia.com/php-upload-immage-to-database.html

Also you can read Ajax image upload system....
http://www.webinfopedia.com/upload-image-using-PHP-ajax.html

Thank You
User avatar
webinfopedia
New php-forum User
New php-forum User
 
Posts: 84
Joined: Sat May 21, 2011 10:26 pm


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 0 guests

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