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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.