erikjan Posted August 28, 2006 Share Posted August 28, 2006 I want to upload the file artist_name.php to a server via a CMSand also get its name into a field in the MYSQL database runningon that machine.When I do the following the filename comes intothe database field, but the file itself is not uploaded to the serverCan someone help me please, how to have the file itselfuploaded also to the server. Many thanks in advance!This is a tiny piece of the code:<?php//CONNECT TO DATABASE include("connect_inc.php");//INSERT NEW RECORD $artist_name_file=$_FILES['artist_name_file']['name']; $object_SQL_insert="INSERT INTO artists (artist_name_file) VALUES ('$artist_name_file')"; $bool=mysql_query($object_SQL_insert);?>----------------------This code is part of the file where the form is:<form action=artists.php method=post enctype="multipart/form-data"> <table width="300" border="0" cellspacing="3" cellpadding="3"> <tr valign="middle" bgcolor="F9F9F9"> <td class="stdtextconfig" width="122">File</td> <td class="stdtextconfig" width="564"> <input type="file" name="artist_name_file" size="45"></td> </tr> <tr bgcolor="F9F9F9"> <td colspan="2"> <div align="center"> <input type="hidden" name="action" value="insert"> <input type="submit" name="Submit" value="OK"> </div> </td> </tr> </table></form> Quote Link to comment Share on other sites More sharing options...
mr. big Posted August 28, 2006 Share Posted August 28, 2006 [code]//INSERT NEW RECORD $artist_name_file=$_FILES['artist_name_file']['name']; $object_SQL_insert="INSERT INTO artists (artist_name_file) VALUES ('$artist_name_file')"; $bool=mysql_query($object_SQL_insert);[/code]You could easily know a lot more than I do, but here's how I'd do it:[code]$a = $_POST['artist_name_file'];if ($a) {$query = "INSERT INTO artists (artist_name_file) VALUES ('$a')";$result = mysql_query ($query);$aid = mysql_insert_id(); // Get the article ID. if ($aid > 0) { // New article has been added. echo ("The artist's name posted successfully into artists as $a at id $aid") <br />"); } else { echo "Something went wrong!"; }} else {echo 'The variable $a didn't get a value';}[/code] Quote Link to comment Share on other sites More sharing options...
erikjan Posted August 28, 2006 Author Share Posted August 28, 2006 Thanks for your time and reply!!But that is not what I meant.I finally found the solution: $artist_name_file=$_FILES['artist_name_file']['name']; if($_FILES['artist_name_file']['size']>0) { $source=$_FILES['artist_name_file']['tmp_name']; $name_file=$_FILES['artist_name_file']['name'];//URL $dest="../" . $name_file; $check=copy($source,$dest); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.