Jump to content

Recommended Posts

The path needs to be absolute i think. Not 100%. The file is going to root because of

 

$path = dirname(__FILE__);

 

so change it to go into the correct directory

 

$path = dirname(__FILE__)."/uploads/";

 

 

I think thats what you want. Assuming uploads is a folder in the root directory

 

 

Sweet i added:

."public_html/uploads/"

 

to the end of that and it's uploading to the right directory.

 

Ok i'm gonna try and add my php ITEM ID script into the new page and see if i can get that working, will come back if that doesn't work  :-\

 

Cheers for help so far dude!

 

peace

Excellent, it now works great!

 

If anyone wants to do this aswell and is new to PHP like me, this uploads an image and saves it with a filename of the ID of a selected news item from the database.

 

Ie You select News story 3, then choose a file. Then it uploads it and saves it as "3.gif"

 

Now i just need to add some validation so it only lets GIFs be uploaded etc, and it's finished!!

 

Thanks so much for your help adam.

 

<html>
<body><form action="uploader.php" method="post"
enctype="multipart/form-data">

<?
mysql_connect("db1", "stanga_1", "pencil"); 
@mysql_select_db("stanga_1") or die ("unable to connect"); 
$query = "SELECT * FROM news ORDER BY date desc";
$result = mysql_query($query); 
$num = mysql_num_rows($result);
mysql_close();
$i = 0;


while ($i < $num)
{ 
$newsno = mysql_result($result,$i,"newsno");
$date = mysql_result($result,$i,"date");
$head = mysql_result($result,$i,"head");
$body = mysql_result($result,$i,"body");
?>

<input name="item" type="radio" id="item" value="<? echo $newsno;    ?>">

<? echo " <span class='style2'>$head</span><br>";


$i++;
}
?>
<Br>
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br /><br>
<input type="submit" name="submit" value="Submit" />
</form></body>
</html> 

 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Delete</title>
<style type="text/css">
<!--
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
-->
</style>
</head>

<body>


<span class="style1">
<?php 

$id = $_POST['item'];
$path = dirname(__FILE__)."public_html/uploads/"; $path = dirname(__FILE__)."/uploads/";

$destination= $path;

$id = $id . ".gif";

if ($_FILES["file"]["error"] > 0)
    {
    echo "Error: " . $_FILES["file"]["error"] . "<br />";
    }
else
{
move_uploaded_file ($_FILES["file"]["tmp_name"] , $destination. $id);
   echo "<meta http-equiv=\"refresh\" content=\"0;URL=in.html\">";
   
}


?>





</body>
</html>

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.