Very new to PHP I'm afraid :rolleyes: . I am trying to code a form which will enable me to insert info into my database. One of the things I want to be able to do is upload images. Everything works find on my localweb (with EasyPHP), but when I try with my free web space it doesn't work, and the field is considered as being empty.

If anyone could suggest why or see any really bad problem then I would be really grateful.😕

Hope you don't mind, but I've posted all my code as I'm not sure where the problem could come from. PLease don't laugh! :p

<?
$connect=mysql_connect("localhost","",""); // obviously taken out password etc
mysql_select_db("");
?>
<html>
<head>
<title>Inscription Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">

</style>
</head>

<body bgcolor="#CCCCCC" text="#990066">
<table width="600" border="0" cellpadding="2" cellspacing="2" class="sharon">
<tr>
<td colspan="2">Welcome to Sharon's World!<br>
<br>
To become a member, please fill in the form below. <br>
</td>
</tr>
<tr>
<td width="30%" height="487">
<form action="<? echo $PHP_SELF ?>" method="post" enctype="multipart/form-data" name="form1">
<p>Name: <br>
<input name="name" type="text" id="name">
<br>
<br>
Surname:
<input name="surname" type="text" id="surname">
</p>
<p>Profession:
<input name="profession" type="text" id="profession">
</p>
<p>Phone:<br>
<input name="phone" type="text" id="phone">
</p>
<p>Postcode:
<input name="postcode" type="text" id="postcode">
</p>
<p>E-mail:<br>
<input name="mail" type="text" id="mail">
</p>
<p> Date of Birth:<br>
<input name="dob" type="text" id="dob" value="0000-00-00">
<br>
<br>
Town:</p>
<p>
<input name="town" type="text" id="town">
</p>
Photo :
<input name="photo" type="file" id="photo">

      <input name="go" type="submit" id="go" value="Send">

  </form></td>
  <td width="70%">&nbsp;</td>

</tr>
</table>
<?
if(isset($go))
{if (empty($name)||empty($surname)||empty($profession)||empty($phone)||empty($postcode)||empty($photo)||empty($mail)||empty($town)) {
die("STOP. Some fields may be empty");}
if (ereg("[a-z|.]+@[[:alpha:]|-]+.[[:alpha:]]",$mail)==0) die ("Please enter a valid e-mail address");
else
{
if(is_uploaded_file($photo)) { move_uploaded_file($photo,"images/$photo_name");};

  $requete="INSERT INTO people(name,surname,profession,phone,postcode,mail,dob,town,photo) VALUES('$name','$surname','$profession','$phone','$postcode','$mail','$dob','$town','$photo_name')";
  mysql_query($requete); 

  if(mysql_insert_id()!=0) 
  {echo "This is the photo you have sent us:<br><img src=images/".$photo_name.">";} 
  else {echo "There was a problem with your form, please try again or contact us";};
  };
  };
  ?>

</body>
</html>
<?
mysql_close($connect);
?>

:eek: :eek: :eek: 😕 :rolleyes:

    Hiya,

    I had the same problem some time ago when I was running the PHP script Gallery and getting file upload problems (empty fields, upload errors)

    I tried everything I could think of, and in desperation, I looked at my php.ini file. And there it was...

    file_uploads=0

    Simply changing this to file_uploads=1, saving php.ini and restarting Apache resolved the issue for me! If you ain't got file_uploads enabled in php.ini, you'll never be able to upload via the browser!

    HTH

    Jonathen

      Thanks for your reply.

      You've really lost me. I'm so new to PHP that I don't if kno what you're talking about! :mad:

      Where can I find the file file_uploads=0 so that I can change it? If you could point me in the right direction I would be most grateful.

      Thanks again,

      Sharon

        Me again,

        I have just tried to run my script on a different server (because I don't know what my ini file is) and it worked better.

        My image name was inserted into my DB and field wasn't considered as being empty, so at least I'm going in the right direction.

        However, I get the following error message

        Warning: Unable to create 'images/Alveole.jpg': Permission denied in /usr/home/mugshotgifts/public_html/sharon_inscription.php on line 80

        Warning: Unable to move '/var/tmp/phpkqbkL8' to 'images/Alveole.jpg' in /usr/home/mugshotgifts/public_html/sharon_inscription.php on line 80

        Line 80 of my code is

        if(is_uploaded_file($photo)) { move_uploaded_file($photo,"images/$photo_name");};

        I think there's probably only a small problem, but I'm soooo new to PHP that I just can't identify it! Anyone know what's going wrong?

          I'm guessing you probably don't have access to the php.ini.
          (It's the initialization file that php uses when it's started. Generally, you need to be a server admin to touch this sucker.)

          Here's what is probably the deal with your file copy failure...
          The PHP user (the user under which PHP runs, ie "nobody" or "www" or "joe") must have write permissions in BOTH the temporary directory and the directory to which it is copying the file. Otherwise, it won't go where it's supposed to go and you'll get nasty parse errors. The likely cause of the file copy failure is permissions. You need to be sure that the directory you're moving the image file to is writable by PHP.

          dig?

            Hi,

            To find out the settings on php.ini, create a new file called phpinfo.php and enter the following line into it:

            <?php phpinfo(); ?>

            Then save it, upload it to the server and go to it (i.e http://mysite.com/phpinfo.php)

            This will tell you the version of PHP, the location of php.ini and will show you the various modules under PHP. Do a search on the page for file_uploads - this will show you whether it is switched on or not (1 if it is on, 0 if it is off)

            If the value is 0, then at the top of the page, look at the path to php.ini (Configuration File (php.ini) Path - i.e /etc/php.ini) Once you know the path to it, you can then find it on your server and edit the file_uploads=0 to file_uploads=1.

            As for line 80, it's trying to create/upload an image to the images directory called Alveole.jpg, but cannot do so due to permissions. As this fails due to permissions, it then cannot move '/var/tmp/phpkqbkL8' to the images directory (the temp file used for creating/uploading the file) because of the aforementioned permissions problem.

            Trying changing the permissions of your images directory to 777 temporarily (type: chmod -R 777 images)

            HTH

            Jonathen

              Thanks for all of that and for your patience . I'm going to have a try in a minute.

              Just two quick questions:

              stimulus:
              what do you mean by making sure that the directory where I will be moving my image file is writable in PHP? The image file is on the same server...

              jonathen:
              I'm going to have a go at the .ini file later on today, so I'll let you know if I manage!
              I'm not very sure what you mean about changing the permissions of my images directory to 777 temporarily. How do I do this and where am meant to type chmod -R 777 images?

              Sorry if I sound really thick but I'm really new to all of this and have been working on PHP all week. It's really interesting though and I think I've already learnt quite a lot but have a hell of a lot still to learn.
              🙂 🙂 🙂 😃

                what do you mean by making sure that the directory where I will be moving my image file is writable in PHP? The image file is on the same server...

                The same thing jonathen means by chmod 777. 🙂
                This is a pretty heavy duty thing to just be getting into php with, but I applaud your ambition.

                UNIX is a multi-user operating system, so directories are "owned" by different users. "Permissions" simply refer to what level of access to a given file or directory a user has.

                "chmod" is a unix command used to change permissions.

                I dug up a pretty quick, yet thorough, guide to understanding fie permissions here:

                http://websiteowner.info/tutorials/server/permissions.asp

                This should help you in your php endeavors as well as give you a peek into the world of unix.

                  Wow!! Wow!! Wow!!

                  It works!!!!

                  I changed the "thing" to 777 and it works! Thank you so much for directing me to that great article. I'm now going to read through it to get a better understanding.

                  Thank you to both of you!!! Yes, I am very ambitious but it's mainly due to the fact that I find PHP very interesting and can't wait to have a better understanding.

                  Thanks again,

                  Sharon

                  😃 😃 :p

                    4 days later

                    i cannot find the item of "upload_file=0"

                    i encounter the same trouble!

                    the following is the detailed infomation of my phpinfo()!

                    PHP Version 4.0.0

                    System Windows NT 5.0 build 2195
                    Build Date May 22 2000
                    Server API CGI
                    Virtual Directory Support disabled
                    Configuration File (php.ini) Path php.ini
                    ZEND_DEBUG disabled
                    Thread Safety enabled

                    This program makes use of the Zend scripting language engine:
                    Zend Engine v1.00, Copyright (c) 1998-2000 Zend Technologies


                    PHP 4.0 Credits


                    Configuration
                    PHP Core
                    Directive Local Value Master Value
                    define_syslog_variables
                    Off Off
                    highlight.bg
                    #FFFFFF #FFFFFF
                    highlight.comment
                    #FF8000 #FF8000
                    highlight.default
                    #0000BB #0000BB
                    highlight.html
                    #000000 #000000
                    highlight.keyword
                    #007700 #007700
                    highlight.string
                    #DD0000 #DD0000
                    allow_call_time_pass_reference
                    On On
                    asp_tags
                    Off Off
                    display_errors
                    On On
                    enable_dl
                    On On
                    error_append_string
                    Off Off
                    error_prepend_string
                    Off Off
                    expose_php
                    On On
                    ignore_user_abort
                    On On
                    implicit_flush
                    Off Off
                    log_errors
                    Off Off
                    magic_quotes_gpc
                    On On
                    magic_quotes_runtime
                    Off Off
                    magic_quotes_sybase
                    Off Off
                    output_buffering
                    Off Off
                    register_argc_argv
                    On On
                    register_globals
                    On On
                    safe_mode
                    Off Off
                    short_open_tag
                    On On
                    sql.safe_mode
                    Off Off
                    track_errors
                    Off Off
                    track_vars
                    On On
                    y2k_compliance
                    Off Off
                    arg_separator
                    & &
                    auto_append_file
                    no value no value
                    auto_prepend_file
                    no value no value
                    doc_root
                    no value no value
                    default_charset
                    no value no value
                    default_mimetype
                    text/html text/html
                    error_log
                    no value no value
                    extension_dir
                    ./ ./
                    gpc_order
                    GPC GPC
                    include_path
                    no value no value
                    max_execution_time
                    30 30
                    open_basedir
                    no value no value
                    safe_mode_exec_dir
                    no value no value
                    upload_max_filesize
                    2097152 2097152
                    upload_tmp_dir
                    no value no value
                    user_dir
                    no value no value
                    variables_order
                    EGPCS EGPCS
                    SMTP
                    localhost localhost
                    browscap
                    no value no value
                    error_reporting
                    2039 2039
                    precision
                    14 14
                    sendmail_from
                    me@localhost.com me@localhost.com
                    sendmail_path
                    no value no value

                    standard
                    Regex Library Bundled library enabled
                    Dynamic Library Support enabled
                    Internal Sendmail Support for Windows 4 enabled

                    Directive Local Value Master Value
                    safe_mode_protected_env_vars
                    LD_LIBRARY_PATH LD_LIBRARY_PATH
                    safe_mode_allowed_env_vars
                    PHP PHP
                    assert.active
                    1 1
                    assert.bail
                    0 0
                    assert.warning
                    1 1
                    assert.callback
                    no value no value
                    assert.quiet_eval
                    0 0

                    com
                    Directive Local Value Master Value
                    allow_dcom
                    Off Off
                    typelib_file
                    no value no value

                    pcre
                    PCRE (Perl Compatible Regular Expressions) Support enabled
                    PCRE Library Version 3.1 09-Feb-2000

                    odbc
                    ODBC Support enabled
                    Active Persistent Links 0
                    Active Links 0
                    ODBC library Win32

                    Directive Local Value Master Value
                    odbc.allow_persistent
                    On On
                    odbc.max_persistent
                    Unlimited Unlimited
                    odbc.max_links
                    Unlimited Unlimited
                    odbc.default_db
                    no value no value
                    odbc.default_user
                    no value no value
                    odbc.default_pw

                    odbc.defaultlrl
                    return up to 4096 bytes return up to 4096 bytes
                    odbc.defaultbinmode
                    return as is return as is
                    odbc.check_persistent
                    On On

                    session
                    Session Support enabled

                    Directive Local Value Master Value
                    session.save_path
                    /tmp /tmp
                    session.name
                    PHPSESSID PHPSESSID
                    session.save_handler
                    files files
                    session.auto_start
                    0 0
                    session.gc_probability
                    1 1
                    session.gc_maxlifetime
                    1440 1440
                    session.serialize_handler
                    php php
                    session.cookie_lifetime
                    0 0
                    session.cookie_path
                    / /
                    session.cookie_domain
                    no value no value
                    session.use_cookies
                    1 1
                    session.referer_check
                    no value no value
                    session.entropy_file
                    no value no value
                    session.entropy_length
                    0 0
                    session.cache_limiter
                    nocache nocache
                    session.cache_expire
                    180 180

                    xml
                    XML Support active

                    mysql
                    MySQL Support enabled
                    Active Persistent Links 0
                    Active Links 0
                    Client API version 3.23.10-alpha

                    Directive Local Value Master Value
                    mysql.allow_persistent
                    On On
                    mysql.max_persistent
                    Unlimited Unlimited
                    mysql.max_links
                    Unlimited Unlimited
                    mysql.default_host
                    no value no value
                    mysql.default_user
                    no value no value
                    mysql.default_password
                    no value no value
                    mysql.default_port
                    no value no value

                    Additional Modules
                    bcmath
                    wddx

                    Environment
                    Variable Value
                    ALLUSERSPROFILE D:\Documents and Settings\All Users
                    CommonProgramFiles D:\Program Files\Common Files
                    COMPUTERNAME ZHF
                    ComSpec D:\WINNT\system32\cmd.exe
                    CONTENT_LENGTH 1482
                    CONTENT_TYPE multipart/form-data; boundary=---------------------------7d21cb33a0270
                    GATEWAY_INTERFACE CGI/1.1
                    HTTPS off
                    HTTP_ACCEPT /
                    HTTP_ACCEPT_LANGUAGE zh-cn
                    HTTP_CONNECTION Keep-Alive
                    HTTP_HOST localhost
                    HTTP_REFERER http://localhost/php/zhanghongfei.php
                    HTTP_USER_AGENT Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
                    HTTP_CONTENT_LENGTH 1482
                    HTTP_CONTENT_TYPE multipart/form-data; boundary=---------------------------7d21cb33a0270
                    HTTP_ACCEPT_ENCODING gzip, deflate
                    HTTP_CACHE_CONTROL no-cache
                    INSTANCE_ID 1
                    LOCAL_ADDR 127.0.0.1
                    NUMBER_OF_PROCESSORS 1
                    Os2LibPath D:\WINNT\system32\os2\dll;
                    OS Windows_NT
                    Path D:\WINNT\system32;D:\WINNT;D:\WINNT\System32\Wbem;D:\KAV2003
                    PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
                    PATH_INFO /php/zhanghongfei.php
                    PATH_TRANSLATED D:\Inetpub\wwwroot\php\zhanghongfei.php
                    PROCESSOR_ARCHITECTURE x86
                    PROCESSOR_IDENTIFIER x86 Family 6 Model 7 Stepping 3, GenuineIntel
                    PROCESSOR_LEVEL 6
                    PROCESSOR_REVISION 0703
                    ProgramFiles D:\Program Files
                    REMOTE_ADDR 127.0.0.1
                    REMOTE_HOST 127.0.0.1
                    REQUEST_METHOD POST
                    SCRIPT_NAME /php/zhanghongfei.php
                    SERVER_NAME localhost
                    SERVER_PORT 80
                    SERVER_PORT_SECURE 0
                    SERVER_PROTOCOL HTTP/1.1
                    SERVER_SOFTWARE Microsoft-IIS/5.0
                    SystemDrive D:
                    SystemRoot D:\WINNT
                    TEMP D:\WINNT\TEMP
                    TMP D:\WINNT\TEMP
                    USERPROFILE D:\Documents and Settings\Default User
                    windir D:\WINNT

                    PHP Variables
                    Variable Value
                    PHP_SELF /php/zhanghongfei.php
                    HTTP_POST_VARS["max_file_size"] 9999999991000
                    HTTP_POST_VARS["submit"] send
                    HTTP_POST_FILES["userfile"] Array
                    (
                    [name] => boydddddddddfdf.jpg
                    [type] => image/pjpeg
                    [tmp_name] => D:\WINNT\TEMP\php2
                    [size] => 1043
                    )

                    HTTP_SERVER_VARS["PHP_SELF"] /php/zhanghongfei.php
                    HTTP_SERVER_VARS["argv"] Array
                    (
                    )

                    HTTP_SERVER_VARS["argc"] 0
                    HTTP_ENV_VARS["ALLUSERSPROFILE"] D:\Documents and Settings\All Users
                    HTTP_ENV_VARS["CommonProgramFiles"] D:\Program Files\Common Files
                    HTTP_ENV_VARS["COMPUTERNAME"] ZHF
                    HTTP_ENV_VARS["ComSpec"] D:\WINNT\system32\cmd.exe
                    HTTP_ENV_VARS["CONTENT_LENGTH"] 1482
                    HTTP_ENV_VARS["CONTENT_TYPE"] multipart/form-data; boundary=---------------------------7d21cb33a0270
                    HTTP_ENV_VARS["GATEWAY_INTERFACE"] CGI/1.1
                    HTTP_ENV_VARS["HTTPS"] off
                    HTTP_ENV_VARS["HTTP_ACCEPT"] /
                    HTTP_ENV_VARS["HTTP_ACCEPT_LANGUAGE"] zh-cn
                    HTTP_ENV_VARS["HTTP_CONNECTION"] Keep-Alive
                    HTTP_ENV_VARS["HTTP_HOST"] localhost
                    HTTP_ENV_VARS["HTTP_REFERER"] http://localhost/php/zhanghongfei.php
                    HTTP_ENV_VARS["HTTP_USER_AGENT"] Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
                    HTTP_ENV_VARS["HTTP_CONTENT_LENGTH"] 1482
                    HTTP_ENV_VARS["HTTP_CONTENT_TYPE"] multipart/form-data; boundary=---------------------------7d21cb33a0270
                    HTTP_ENV_VARS["HTTP_ACCEPT_ENCODING"] gzip, deflate
                    HTTP_ENV_VARS["HTTP_CACHE_CONTROL"] no-cache
                    HTTP_ENV_VARS["INSTANCE_ID"] 1
                    HTTP_ENV_VARS["LOCAL_ADDR"] 127.0.0.1
                    HTTP_ENV_VARS["NUMBER_OF_PROCESSORS"] 1
                    HTTP_ENV_VARS["Os2LibPath"] D:\WINNT\system32\os2\dll;
                    HTTP_ENV_VARS["OS"] Windows_NT
                    HTTP_ENV_VARS["Path"] D:\WINNT\system32;D:\WINNT;D:\WINNT\System32\Wbem;D:\KAV2003
                    HTTP_ENV_VARS["PATHEXT"] .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
                    HTTP_ENV_VARS["PATH_INFO"] /php/zhanghongfei.php
                    HTTP_ENV_VARS["PATH_TRANSLATED"] D:\Inetpub\wwwroot\php\zhanghongfei.php
                    HTTP_ENV_VARS["PROCESSOR_ARCHITECTURE"] x86
                    HTTP_ENV_VARS["PROCESSOR_IDENTIFIER"] x86 Family 6 Model 7 Stepping 3, GenuineIntel
                    HTTP_ENV_VARS["PROCESSOR_LEVEL"] 6
                    HTTP_ENV_VARS["PROCESSOR_REVISION"] 0703
                    HTTP_ENV_VARS["ProgramFiles"] D:\Program Files
                    HTTP_ENV_VARS["REMOTE_ADDR"] 127.0.0.1
                    HTTP_ENV_VARS["REMOTE_HOST"] 127.0.0.1
                    HTTP_ENV_VARS["REQUEST_METHOD"] POST
                    HTTP_ENV_VARS["SCRIPT_NAME"] /php/zhanghongfei.php
                    HTTP_ENV_VARS["SERVER_NAME"] localhost
                    HTTP_ENV_VARS["SERVER_PORT"] 80
                    HTTP_ENV_VARS["SERVER_PORT_SECURE"] 0
                    HTTP_ENV_VARS["SERVER_PROTOCOL"] HTTP/1.1
                    HTTP_ENV_VARS["SERVER_SOFTWARE"] Microsoft-IIS/5.0
                    HTTP_ENV_VARS["SystemDrive"] D:
                    HTTP_ENV_VARS["SystemRoot"] D:\WINNT
                    HTTP_ENV_VARS["TEMP"] D:\WINNT\TEMP
                    HTTP_ENV_VARS["TMP"] D:\WINNT\TEMP
                    HTTP_ENV_VARS["USERPROFILE"] D:\Documents and Settings\Default User
                    HTTP_ENV_VARS["windir"] D:\WINNT

                    :o

                      Write a Reply...