Jump to content


Photo

Uploading a php file


  • Please log in to reply
2 replies to this topic

#1 erikjan

erikjan
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 28 August 2006 - 03:08 PM

I want to upload the file artist_name.php to a server via a CMS
and also get its name into a field in the MYSQL database running
on that machine.

When I do the following the filename comes into
the database field, but the file itself is not uploaded to the server

Can someone help me please, how to have the file itself
uploaded 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>

#2 mr. big

mr. big
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 28 August 2006 - 03:36 PM

//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);

You could easily know a lot more than I do, but here's how I'd do it:

$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';
}

"Every monkey thinks its children are beautiful."

#3 erikjan

erikjan
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 28 August 2006 - 05:03 PM

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);
  }




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users