SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    For some mysterious reasons Photo upload is not working

    Hi,

    I am using the same Php/HTML code I have used in other pages to allow for image uploading, but somehow
    it is not working on a new page I am building!

    The HTML part is (in super summary format):
    Code:
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
    <input type="hidden" name="MAX_FILE_SIZE" value="10000">
    <input type="file" name="uploadedfile">
    <input type="submit" name="submit_foto" value="Submit My Thumb-nail Foto" class="form_button">
    </form>
    The Php part that is to check & upload the images is:

    PHP Code:
    if (isset($_POST['submit_foto'])) {

    if (
    eregi('^image/p?jpeg(;.*)?$'$_FILES['uploadedfile']['type'])) {
    $filetype 'jpg';
    } else if (
    eregi('^image/gif(;.*)?$'$_FILES['uploadedfile']['type'])) {
    $filetype 'gif';
    } else {
    $error 'Thumb-nail photo has the wrong file type. Acceptable image formats are either gif or jpg.';
    array_push($error_list$error);

    }
    //CLOSES if (eregi...........

    echo 'File Type: ' $_FILES['uploadedfile']['type'] . '<p>'
    and I am getting error message that File type is not "either gif or jpg" and when I check it via the echo command I see
    that the $_FILES['uploadedfile']['type'] is empty!

    What is going on?
    What am I missing?

    ThanX,

    P.S., I may have posted this message before in a wrong thread, if so please ignore that and reply here.
    Last edited by spikeZ; Jul 19, 2012 at 02:42.

    Anoox search engine volunteer

    www.anoox.com

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,805
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Are you getting anything through the $_FILES array at all?

    Dump the contents out using print_r($_FILES) and see if there is anything.

    One thing I did notice is that 10k is a pretty small MAX_FILE_SIZE.....!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    PHP Code:
    var_dump$_FILES); 
    Should always be your first port of call.

    Check the return value of:
    PHP Code:
     $_FILES['uploadedfile']['error'
    Very carefully. Upload error codes.

    Your code should analyse this number before trying to do anything, if it is not 0 - something has gone wrong, and you could consider feeding that back to the user - or logging it somewhere.

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    You code is also flawed in so many ways. You should scrap it.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hello Cups,

    As per your suggestion I printed out these 2 and it is showing:

    array(1) { ["uploadedfile"]=> array(5) { ["name"]=> string(20) "chilean_miners_a.jpg" ["type"]=> string(0) "" ["tmp_name"]=> string(0) "" ["error"]=> int(2) ["size"]=> int(0) } } var dump:

    Files Error: 2


    So what now!
    ThanX.

    Quote Originally Posted by Cups View Post
    PHP Code:
    var_dump$_FILES); 
    Should always be your first port of call.

    Check the return value of:
    PHP Code:
     $_FILES['uploadedfile']['error'
    Very carefully. Upload error codes.

    Your code should analyse this number before trying to do anything, if it is not 0 - something has gone wrong, and you could consider feeding that back to the user - or logging it somewhere.

    Anoox search engine volunteer

    www.anoox.com

  6. #6
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hello spikeZ,

    No the issue is not the MAX_FILE_SIZE, since I have increased that ti much higher and still same strange Error!
    Also of course is not that since the Error is happening before that as per the Error message that the File_type is missing.

    So as per your and cups suggestion I have printed out the var_dump($_FILES) which you can see below.

    ThanX,

    Anoox search engine volunteer

    www.anoox.com

  7. #7
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,069
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WorldNews View Post
    Hello spikeZ,

    No the issue is not the MAX_FILE_SIZE, since I have increased that ti much higher and still same strange Error!
    Also of course is not that since the Error is happening before that as per the Error message that the File_type is missing.

    So as per your and cups suggestion I have printed out the var_dump($_FILES) which you can see below.

    ThanX,
    I think you may want to check your MAX_FILE_SIZE hidden field again. As that is exactly what it is reporting the error to be.

    UPLOAD_ERR_FORM_SIZE
    Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.
    From: http://www.php.net/manual/en/feature...oad.errors.php

  8. #8
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hey ThanX.

    I fixed the problem.
    FYI, the problem was I was not loading the data for MAX_FILE_SIZE via the Php code that I had to do so for the rest of
    the page and somehow I was missing that omission!

    Thanx to all anyway.

    Quote Originally Posted by cpradio View Post
    I think you may want to check your MAX_FILE_SIZE hidden field again. As that is exactly what it is reporting the error to be.
    From: http://www.php.net/manual/en/feature...oad.errors.php

    Anoox search engine volunteer

    www.anoox.com

  9. #9
    SitePoint Member
    Join Date
    Jul 2012
    Location
    kolkata
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this code i m using you can replace yours with it

    it is running well

    <?php include_once("../config/config.php"); error_reporting(0);?><?php if(isset($_REQUEST['s_x'])) {
    if($_FILES['f2']['name']=='')
    {
    $msg="Select Your Image";
    }
    else
    {
    mysql_query("insert into portfolio(poid,p_image,p_category,p_active_ind,p_uploaddate)values('','','".$_POST['jumpMenu']."','Y',NOW())") or die(mysql_error());
    $filename=basename($_FILES['f2']['name']);

    $ext=substr($filename,strpos($filename,'.')+1);

    $id=mysql_insert_id();
    $newname='img_'.$id.'.'.$ext;
    if (($ext== "gif")|| ($ext== "jpeg")|| ($ext== "jpg")|| ($ext== "png"))
    {

    if(move_uploaded_file ($_FILES['f2']['tmp_name'],dirname(__FILE__)."/portfolio/".$newname))
    {
    mysql_query("update portfolio set p_image ='".$newname."'where poid ='".$id."'")or die(mysql_error());//picture update

    }

    }
    else
    {
    $msg="Upload Only Image Formatt";
    }
    }
    }
    ?>


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
  •