PDA

View Full Version : help with uploader


swissbeets
07-28-2008, 06:05 PM
I am using the uploader.php that is in a tutorial to upload pictures to my site. but when i upload them everything is working fine except that the pictures are not being saved in my images folder(everything being, the name is saving in the database and being called correctly)

maybe another set of eyes could help me spot the problem, here is my code


<?php require_once("includes/session.php"); ?>
<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php confirm_logged_in();
//echo "<pre>";
//print_r($_FILES);
//echo "</pre>";
$target_path = "images/".$_FILES['uploadedfile']['name'];
move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$target_path);
$image_source = mysql_prep($_FILES['uploadedfile']['name']);
$id = $_GET['page'];
$query = "UPDATE pages SET
image_source = '$image_source'
WHERE id = $id";

$result = mysql_query($query);
if (mysql_affected_rows() == 1) {
redirect_to("edit_page.php");
} else {
// Failed
$message = "The product update failed.";
$message .= "<br />". mysql_error();
echo $message;
}?>


here is where the actualy information is coming from


<form enctype="multipart/form-data" action="uploader.php?page=<?php echo $sel_page['id']; ?>" method="POST">

<input type="hidden" name="MAX_FILE_SIZE" value="100000" />

Choose a file to upload: <input name="uploadedfile" type="file" value= "<?php print $sel_page['image_source']; ?>"/>

<input type="submit" value="Upload File" />

</form>

edbr
07-29-2008, 01:19 AM
where did you get the script? difficult to say but check the target folder is named correctly in $target_path where ever that is

davidj
07-29-2008, 08:15 AM
and make sure you have permission to write to that target dir

swissbeets
07-30-2008, 07:18 PM
i got it, it was the target path thank you

davidj
07-30-2008, 07:31 PM
quick heads up

dont echo any messages in the php

always assign to a var and echo the var in the html

swissbeets
07-30-2008, 07:34 PM
really? ok thanks i didnt know that

davidj
07-30-2008, 07:41 PM
it gives you complete control over message style and position and is valid markup

anything not inside the <body tag should not be output