Jump to content

Uploading a php file


erikjan

Recommended Posts

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>
Link to comment
https://forums.phpfreaks.com/topic/18906-uploading-a-php-file/
Share on other sites

[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]
Link to comment
https://forums.phpfreaks.com/topic/18906-uploading-a-php-file/#findComment-81665
Share on other sites

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);
  }
Link to comment
https://forums.phpfreaks.com/topic/18906-uploading-a-php-file/#findComment-81704
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.