Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I can't get file upload to work

Status
Not open for further replies.

richclever

IS-IT--Management
Oct 5, 2000
127
FR
Hi,

This is probably a really simple question but I can't figure out where I am going wrong.

I want to upload images from a form that also has other info in it but I can't get the images to upload.

My form html is as follows.

Code:
<form enctype="multipart/form-data" form action="insert.php" method="POST"  >
        <table width="100%" border="1" bordercolor="#99CCFF">
          </tr>
          <tr> 
            <td><font face="Verdana, Arial, Helvetica, sans-serif">Name</font></td>
            <td><input name="name" type="text" id="name"></td>
          </tr>
          <tr> 
            <td><font face="Verdana, Arial, Helvetica, sans-serif">Age</font></td>
            <td><input name="age" type="text" id="age"></td>
          </tr>
          <tr> 
            <td><font face="Verdana, Arial, Helvetica, sans-serif">Description</font></td>
            <td><textarea name="description" id="description"></textarea></td>
          </tr>
          <tr> 
            <td><font face="Verdana, Arial, Helvetica, sans-serif">Upload image</font></td>
            <input type ="hidden" name = "MAX_FILE_SIZE" value ="30000">
            <td><input name="imagefile" type="file" id="imagefile"></td>
          </tr>
          <tr>
            <td><input type="submit" name="Submit" value="Submit"></td>
            
            <td>&nbsp;</td>
          </tr>
        </table>
      </form>

My php in insert.php is as follows

Code:
<?
require ('../conf.php');

$query="INSERT INTO catinfo ( name, age, description) VALUES ( '$name', '$age', '$description' )";
$result = @mysql_query($query);
$uid= mysql_insert_id();

$filename = $uid . '.jpg';
$add = "..\images\$filename";


if (move_uploaded_file($_FILES['imagefile']['tmp_name'], $add)) {
 	echo "file uploaded";
 	}else{echo "Failed to upload file Contact Site admin to fix the problem";
 	}

?>

As far as I'm concerned, the information should be written to the database (as indeed it is) and the file should be written to the directory (the file name is the id number in the database which is auto incrementing)

I know that php is et up correctly - I can upload using other ready made scripts no problems; but I can't get this to work.

Any ideas??

Thanks
Rich
 
It looks to me like you're mixing your backslashes and forward slashes:

[tt]require ('..[red]/[/red]conf.php');[/tt]
versus
[tt]$add = "..[red]\[/red]images[red]\[/red]$filename";[/tt]

In a doublequoted string literal, backslash is an escape character.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I can't believe I made that mistake!!!

Thanks a lot for pointing out my stupidity - no wonder it didn't work!

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top