SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php image fileuploader not working

    Hi there,

    I am working on a image uploader for a new project and not sure what is coursing my image problem ive tried to play around with it but whenever i upload an image uploader not sure why its causing this problem

    is this what i have at the moment.i am getting this kind of error

    Warning: copy(../images/Sunset.jpg) [function.copy]: failed to open stream: No such file or directory in C:\Program Files\xampp\htdocs\RealEstate\admin\manadmin.php on line 265
    upload failed!

    This is my code i have atm.

    PHP Code:
    <tr>
                                        <
    th>Picture</th>
                                        <
    th><input type="hidden" value="aid" value="'.$_GET['aid'].'">
                                        <
    input type="file" name="userfile">
                                        </
    th>
                                    </
    tr>
                                    <
    tr>
                                        <
    th>Phone</th>
                                        <
    th><input type="text" name="phone" value='.$data['phone'].'></th>
                                    </
    tr>
                                    <
    tr>
                                        <
    th>Fax</th>
                                        <
    th><input type="text" name="fax" value='.$data['fax'].'></th>
                                    </
    tr>
                                    <
    tr>
                                        <
    th><input type="submit" name="pc" value="Update"></th>
                                    </
    tr>
                                </
    table>
                                </
    form>';
                                //Submitting update info
                                if(isset($_POST['
    pc']))
                                {
                                    $file=$_POST['
    userfile']['name'];
                                    $aid=$_POST['
    aid'];
                                    $userfile=$_FILES['
    userfile'];
                                    $user=$_POST['
    user'];
                                    $pass=$_POST['
    pass'];
                                    $email=$_POST['
    email'];
                                    $fname=$_POST['
    fname'];
                                    $logo=$_POST['
    logo'];
                                    $phone=$_POST['
    phone'];
                                    $fax=$_POST['
    fax'];
                                    if($file || $aid || $user || $pass || $fname || $logo || $phone || $fax || $userfile || $file)
                                    {
                                        //
                                        $path = "../images/";
                                            $max_size = 200000;
                                            if (!isset($HTTP_POST_FILES['
    userfile'])) exit;
                                            
                                            if (is_uploaded_file($HTTP_POST_FILES['
    userfile']['tmp_name']))
                                            {
                                                if ($HTTP_POST_FILES['
    userfile']['size']>$max_size)
                                                {
                                                     echo "The file is too big<br>\n";
                                                     exit;
                                                }
                                                if(($HTTP_POST_FILES['
    userfile']['type']=="image/gif") ||
                                                    ($HTTP_POST_FILES['
    userfile']['type']=="image/pjpeg") ||
                                                    ($HTTP_POST_FILES['
    userfile']['type']=="image/jpeg"))
                                                {
                                                    //
                                                    if (file_exists($path . $HTTP_POST_FILES['
    userfile']['name'])) 
                                                    {     
                                                        echo "The file already exists<br>\n"; 
                                                        exit;
                                                     }        
                                                $res = copy($HTTP_POST_FILES['
    userfile']['tmp_name'], $path .
                                                $HTTP_POST_FILES['
    userfile']['name']);
                                                if (!$res)
                                                {
                                                 echo "upload failed!<br>\n";
                                                exit;
                                                }
                                                else
                                                {
                                                    //
                                                    include("../dbconnect.php");
                                                    $r="update admin set picture='
    $file',email='$email',name='$name',logo='$logo',phone='$phone',fax='$fax',password='$pass',username='$user' WHERE aid='$aid'";
                                                    $rQ=mysqli_query($con,$r);
                                                    if(!$r)
                                                    {
                                                        //
                                                        echo "Error".mysqli_error($con);
                                                        //
                                                    }
                                                    else
                                                    {
                                                    //
                                                        echo "upload sucessful<br>\n
                                                        The File has been placed in the images folder<br/>"; 
                                                    }
                                                }
                                                    //
                                                } 
                                                else
                                                {
                                                echo "Wrong file type<br>\n";
                                                exit;
                                                }
                                            }
                                            //
                                        }
                                        //
                                    }
                                } 
    What can i do about this and get this fixed?

    Thanks,William

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think as the error itself says that the destination folder does not exists or something like that. What is your folders structure and where your script file lies in? Do you have already created a folder named 'images' inside 'RealEstate' folder? If yes then it should work. And just curious to know are you on lower than PHP 4 or so? Otherwise why not $_FILES instead of $HTTP_POST_FILES?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •