Jump to content

File Is Not Uploading


podja

Recommended Posts

Hey,

 

I have been trying to integrate a file upload script into a script that inserts stuff into the database.

 

I've been trying all day and don't see why it wont work. It works fine by itself, but when added to the other script it wont work.

 

Heres the full script I'm using (Its a bit long but I'm sure you can help!)

 

Heres the form I am using:

<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<h1>Update FunVid.net</h1>
<p>Fill in the forms below to update FunVid.net</p>

<?php
if(isset($_POST['submit'])) {
	include('insert.php');
}
?>

<fieldset>
<form name="update01" method="post" enctype="multipart/form-data">
<label for="title">Title:</label><br />
<input type="text" name="title" id="title" tabindex="1" value="<?php if(isset($title)) {echo $title;} ?>" /><br />

<label for="desc">Video Description</label><br />
<textarea name="desc" id="desc" rows="10" cols="100" tabindex="2"><?php if(isset($desc)) {echo $desc;} ?></textarea><br />

<label for="embed">YouTube Embed Code (Will be validated)</label><br />
<textarea name="embed" id="embed" rows="10" cols="100" tabindex="3"><?php if(isset($embed)) {echo $embed;} ?></textarea><br />

<label for="img">Image To Upload</label><br />
<input type="file" name="imgfile" id="imgfile" tabindex="4" />
<br />

<input type="submit" name="submit" id="submit" value="Update FunVid.net!" />
</form>
</fieldset>
</body>
</html>

 

And heres the PHP I am using:

<?php

// Insert Code | Code To Insert Stuff Into Database

include('connect.php');

// Get The Values From The Form
$title = $_POST['title'];
$desc = $_POST['desc'];
$embed = $_POST['embed'];
$embed = stripslashes($embed);
$date = date("d/m/y");

// Image Upload Variable


// Create matches array for Youtube ccde validator
$matches = array();

// create the errors array
$errors = array();


// Validate the title input
if(strlen($title) < 5) {
	$errors[] = 'Your Title Needs To Be A Bit Longer Than That!';
}

// Validate the description input
if(strlen($desc) < 20) {
	$errors[] = 'Your Description Needs To Be A Bit Longer Than That!';
}

// Validate the embed input
if(strlen($embed) < 30) {
	$errors[] = 'You Need To Embed Your YouTube Video!';
}

// If no errors
if(empty($errors)) {


	// The code to validate youtube input
	$i = strpos($input,'youtube.com/v/');
	$length = strlen('youtube.com/v/');

	while ( $i !== FALSE) {
		$l = strpos($input,'"',$i);
		if ($l !== FALSE) {
			$matches[] = substr($input,$i+$length,$l-$i-$length);
		}
		 $i = strpos($input,'youtube.com/v/',$l);
	}

	$moviecode = $matches[0];

	$embed = "<object type=\"application/x-shockwave-flash\" data=\"http://www.youtube.com/v/$moviecode\" width=\"425\" height=\"350\"><param name=\"movie\" value=\"http://www.youtube.com/v/$moviecode\" /></object>";

	$uploadpath = "uploads/";
	$uploadpath = $uploadpath . basename( $_FILES['imgfile']['name']);
	move_uploaded_file($_FILES['imgfile']['tmp_name'], $uploadpath);

	$query = "INSERT INTO `updates`
	(`title`, `desc`, `embed`, `img`, `date`)
	VALUES ('$title', '$desc', '$embed', '$img', '$date')";

	$exe = mysql_query($query);


} else {

	foreach($errors as $error) {
    		echo "<p class=\"errors\">$error</p>";
	}
}

?>

 

I dont get any errors and everything inserts into the database fine. Its just the image wont upload.

 

Cheers.

 

P.S - I have definately set the permissions to 777 before you ask, hehe.

 

Link to comment
Share on other sites

not sure but iv noticed that u have left out the action statement in ur form tags.

 

yours  -  <form name="update01" method="post" enctype="multipart/form-data">

 

mine  -  <form action='movieReg.php' method='post' enctype='multipart/form-data'>

 

 

also i dont c an indication as to the file type/ extension that u r trying to upload.

eg.  if (($_FILES['file']['type'] == 'image/bmp'||'image/jpeg') && ($_FILES['file']['size'] < 50000))

Link to comment
Share on other sites

Anyone?

 

I know your all geniuses  :D Someone must have an answer!

 

We aren't all genuises. as much as I can say is. If you havent checked already. Try to compare with other file upload scripts to yours and see how they work to grasp the concept how yours should work in a similiar way. I can't really find anything wrong.  besides this.

 

<form name="update01" method="post" enctype="multipart/form-data">
<label for="title">Title:</label><br />
<input type="text" name="title" id="title" tabindex="1" value="<?php if(isset($title)) {echo $title;} ?>" /><br />

<label for="desc">Video Description</label><br />
<textarea name="desc" id="desc" rows="10" cols="100" tabindex="2"><?php if(isset($desc)) {echo $desc;} ?></textarea><br />

<label for="embed">YouTube Embed Code (Will be validated)</label><br />
<textarea name="embed" id="embed" rows="10" cols="100" tabindex="3"><?php if(isset($embed)) {echo $embed;} ?></textarea><br />

<label for="img">Image To Upload</label><br />
<input type="file" name="imgfile" id="imgfile" tabindex="4" />
<br />

<input type="submit" name="submit" id="submit" value="Update FunVid.net!" />

Unless the stored variables come from insert.php

 

 

Of course I know nothing about file uploads. Buuut Im just browsing along.

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.