www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Server-Side Development > PHP

    PHP Discussion and technical support for using and deploying PHP based websites.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 03-07-2006, 12:37 PM
    jogol jogol is offline
    backseat driver
     
    Join Date: Feb 2005
    Posts: 308
    storing to db via form + optional image upload

    hi experts,

    i am referring to this thread by bokeh entitled "How to: Upload images using PHP".

    i want to achieve a solution where one can add a news item to a mysql db and optionally attach a picture too.

    so i modified the upload.form.php and added 2 more form fields: "headline" and "text".

    next i edited upload.processor.php so that additionally the values of the fields "headline" and "text" as well as the location of the uploaded image on the server get stored in a mysql table.

    that works perfectly as long as there is a picture attached and it doesnīt exceed the $max_file_size.

    since i want to make the image upload optional i tried some if-else statements in upload.processor.php to avoid getting errors when there is no pic attached.

    no surprise to me that none of my attempts worked so iīm kindly asking for your help to achieve something like this:

    PHP Code:
    if (there was a picture selected in upload.form.php) {
    // ...do what bokehīs original script does (including error checking) + store info in db...
    } else {
    // ...only store the values of the fields "headline" and "text" into the db and ignore that an image is missing...
    my problem is to find the right if-statement. i tried if (strlen($_FILES[$fieldname]['tmp_name']) > 1) but then i donīt get any error msg when max file size is exceeded.

    any ideas?

    thanks in advance,
    jogol
    __________________
    free music: comatronic
    Reply With Quote
      #2  
    Old 03-08-2006, 04:40 AM
    bokeh's Avatar
    bokeh bokeh is offline
    Keep it simple, stupid!
     
    Join Date: Jan 2005
    Location: Alicante (Spain)
    Posts: 7,708
    PHP Code:
    if($_FILES[$fieldname]['error'] !== 0)
    {
        
    // no image was uploaded
    }
    Reply With Quote
      #3  
    Old 03-08-2006, 07:13 AM
    jogol jogol is offline
    backseat driver
     
    Join Date: Feb 2005
    Posts: 308
    thanks
    __________________
    free music: comatronic
    Reply With Quote
      #4  
    Old 08-14-2006, 02:14 AM
    binhaus binhaus is offline
    Registered User
     
    Join Date: Jul 2006
    Posts: 44
    use my solution... i thinh that the best way.. affter i read many upload image php + image name stored in data mysql
    notices that i have ask for some one help me here for that .. but mostly no one find out my problems in my scripts.. at the end i found my selft ( that stupid bugs) i just forget to put the ( enctype="multipart/form-data" ) in the form ..
    read my post and put this one in.. all will work..
    explain : you can call the funtion uploadimg() any time .. like $nameimagewillstoreindata=@uploadimg() then you can store the $nameimagewillstoreindata affter you call it.. .. the convenian is this php script only one file.. http://www.webdeveloper.com/forum/sh...d.php?t=117029
    now i trying to use it as muti uploader with ajax... if anyone have solution please help me..thanks
    ragards..
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 03:14 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.