upload script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ericburnard
Forum Contributor
Posts: 104
Joined: Wed Jun 15, 2005 5:11 pm
Location: Chesterfield, UK

upload script

Post by ericburnard »

hi there. i am putting a media page on my website which uses mysql. i have written the two scripts and everything is working apart form uploading. i dont know how to make it upload to a certain folder and the insert just the file name into the database (ie. upload from C:/my documents/web stuff/music/song.mp3 uploads it to a space on the server and adds song.mp3 to the database.)
the codes i have written so far are -

upload.php

Code: Select all

<?php
include('http://eric.madashatters.com/header.inc')
?>

<center>
<div class="normalText">
<form action="http://eric.madashatters.com/media/upload2.php" method="post" name="post">
File Name - 
<input type="text" name="name" size="48" class="textbox"><br>

<input type="hidden" name="date" size="48" class="textbox" value="
<?
echo date("dS M Y");
?>">

File - 
<input type="file"><br>

Type - 
<input type="text" name="type" size="48" class="textbox"><br>

Size - 
<input type="text" name="size" size="48" class="textbox"><br>

<input type="submit" value=" Submit " class="textbox">
</form>
</div>
<SCRIPT language="JavaScript">
<!--
startclock();
//-->
</SCRIPT>
</center>
<?php
include('http://eric.madashatters.com/footer.inc')
?>
upload2.php

Code: Select all

<?
include('http://eric.madashatters.com/header.inc')
?>

<?php

// Make a MySQL Connection
mysql_connect("localhost", "madashat_eric", "gateway2") or die(mysql_error());
mysql_select_db("madashat_media") or die(mysql_error());

if(get_magic_quotes_gpc())
{
  $_POST["name"] = stripslashes($_POST["name"]);
  $_POST["date"] = stripslashes($_POST["date"]);
  $_POST["file"] = stripslashes($_POST["file"]);
  $_POST["type"] = stripslashes($_POST["type"]);
  $_POST["size"] = stripslashes($_POST["size"]);
 
}
$name = $_POST["name"];
$date = $_POST["date"];
$file = $_POST["file"];
$type = $_POST["type"];
$size = $_POST["size"];


mysql_query("INSERT INTO media
(name, date, file, type, size) VALUES('$name', '$date', '$file', '$type', '$size' ) ")
or die(mysql_error());

?>
<BR><BR><center>File Uploaded. <a href="http://eric.madashatters.com/">Return</a>!<BR><BR>
<?
include('http://eric.madashatters.com/footer.inc')
?>
thanks again
Eric
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

User avatar
ericburnard
Forum Contributor
Posts: 104
Joined: Wed Jun 15, 2005 5:11 pm
Location: Chesterfield, UK

Post by ericburnard »

anjanesh wrote:file-upload
Use move_uploaded_file
ok thanks for that. i have tryed it and i get this error

Code: Select all

Warning:  move_uploaded_file(http://eric.madashatters.com/media/1.jpg): failed to open stream: HTTP wrapper does not support writeable connections. in /home/madashat/public_html/eric/media/test.php on line 9

Warning:  move_uploaded_file(): Unable to move '/var/tmp/php5ZIDQe' to 'http://eric.madashatters.com/media/1.jpg' in /home/madashat/public_html/eric/media/test.php on line 9
Possible file upload attack!
Here is some more debugging info:Array
(
    &#1111;userfile] => Array
        (
            &#1111;name] => 1.jpg
            &#1111;type] => image/pjpeg
            &#1111;tmp_name] => /var/tmp/php5ZIDQe
            &#1111;error] => 0
            &#1111;size] => 38935
        )

)
i have had a read of the move_uploaded_file but dont quite understand what it is used for or where to put it :s could you explain it for me please.

Thanks again
Eric
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Code: Select all

move_uploaded_file($_FILES['userfile']['tmp_name'],$_FILES['userfile']['name'])
Last edited by anjanesh on Tue Aug 02, 2005 10:35 am, edited 1 time in total.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Here's a tutorial I wrote pending review by the tutorials team.

viewtopic.php?t=35972 , it's the second post
User avatar
ericburnard
Forum Contributor
Posts: 104
Joined: Wed Jun 15, 2005 5:11 pm
Location: Chesterfield, UK

Post by ericburnard »

scrotaye wrote:Here's a tutorial I wrote pending review by the tutorials team.

viewtopic.php?t=35972 , it's the second post
hey than ks for that im going to have a playaround with the whole of my site tomorrow so ill tell you then if it worked :d

thanks again
Eric
Post Reply