Upload images to a folder script problem

Thread Solved

Join Date: Feb 2008
Posts: 52
Reputation: Scottmandoo is an unknown quantity at this point 
Solved Threads: 0
Scottmandoo's Avatar
Scottmandoo Scottmandoo is offline Offline
Junior Poster in Training

Upload images to a folder script problem

 
0
  #1
Mar 7th, 2008
Alright this is my code, the error im getting is in red

<?php

include("dbinfo.inc.php");

$tut_name     = $_POST['tut_name'];
$tut_link     = $_POST['tut_link'];
$tut_program  = $_POST['tut_program'];
$tut_category = $_POST['tut_category'];
$tut_video    = $_POST['tut_video'];
$tut_download = $_POST['tut_download'];
$tut_image    = $_FILES['tut_image']['name'];

function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}

if (empty($tut_image)) {
	$result = '<font color=FFFFFF>Please choose a photo to upload</font>';
	$error++;
}
else {
		$filename = stripslashes($tut_image);
		$extension = getextension($filename);
		$extension = strtolower($extension);
		if (($extension !== "jpg") && ($extension !== "jpeg") && ($extension !== "png") && ($extension !== "gif")) {
			$result = '<font color=FFFFFF>Unknown file extension, please try again</font>';
			$error++;
		}
		else {
			$tmpFile = $_FILES['tut_image']['tmp_name'];
			$size = getimagesize($tmpFile);
			$sizekb = filesize($tmpFile);
			if ($sizekb > 10000) {
				$result = '<font color=FFFFFF>The image has exceeded the size limit, please try again</font>';
				$error++;
			}
			else {
				$imageName = '../images/tutorials/' . time() . '.' . $extension;
				$copy = copy($tmpFile, $imageName);
				if (!$copy) {
					$result = '<font color=FFFFFF>Image upload unsuccessful, please try again</font>';
					$error++;
				}
			}
		}
}
if ($error > 0) {
	echo $result;
}
else {
	$con = mysql_connect('localhost',$username,$password);
	@mysql_select_db($database) or die( "Unable to select database");
	$sql = "INSERT INTO `tutorials` VALUES ('','$tut_name','$tut_link','$tut_program','$tut_category','$tut_video','$tut_download','$imageName')";
	$query = mysql_query($sql) or die('Error: ' . mysql_error());
}

mysql_close();

?>

I have also CHMODed my file destination to 777 permision
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 121
Reputation: Auzzie is an unknown quantity at this point 
Solved Threads: 16
Auzzie Auzzie is offline Offline
Junior Poster

Re: Upload images to a folder script problem

 
0
  #2
Mar 7th, 2008
I'm not 100% sure (just woken up and skimmed the code) but arent you trying to convert a directory into a file on your copy command?

Also i believe there is an image part of the multi dimensional array that is the bit you need to copy, not just the name.

If not then ignore the post and i will wake up and try again
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Upload images to a folder script problem

 
0
  #3
Mar 7th, 2008
i look over my code again and i can't see the problem. i have used this code a dozen times and never had a problem with it. are you sure its not the server.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Upload images to a folder script problem

 
1
  #4
Mar 7th, 2008
try this:

  1. <?php
  2.  
  3. include("dbinfo.inc.php");
  4.  
  5. $tut_name = $_POST['tut_name'];
  6. $tut_link = $_POST['tut_link'];
  7. $tut_program = $_POST['tut_program'];
  8. $tut_category = $_POST['tut_category'];
  9. $tut_video = $_POST['tut_video'];
  10. $tut_download = $_POST['tut_download'];
  11. $tut_image = $_FILES['tut_image']['name'];
  12.  
  13. function getExtension($str) {
  14. $i = strrpos($str,".");
  15. if (!$i) { return ""; }
  16. $l = strlen($str) - $i;
  17. $ext = substr($str,$i+1,$l);
  18. return $ext;
  19. }
  20.  
  21. if (empty($tut_image)) {
  22. $result = '<font color=FFFFFF>Please choose a photo to upload</font>';
  23. $error++;
  24. }
  25. else {
  26. $filename = stripslashes($tut_image);
  27. $extension = getextension($filename);
  28. $extension = strtolower($extension);
  29. if (($extension !== "jpg") && ($extension !== "jpeg") && ($extension !== "png") && ($extension !== "gif")) {
  30. $result = '<font color=FFFFFF>Unknown file extension, please try again</font>';
  31. $error++;
  32. }
  33. else {
  34. $tmpFile = $_FILES['tut_image']['tmp_name'];
  35. $sizekb = filesize($tmpFile);
  36. if ($sizekb > 10000) {
  37. $result = '<font color=FFFFFF>The image has exceeded the size limit, please try again</font>';
  38. $error++;
  39. }
  40. else {
  41. $imageName = 'images/tutorials/' . time() . '.' . $extension;
  42. $copy = copy($tmpFile, $imageName);
  43. if (!$copy) {
  44. $result = '<font color=FFFFFF>Image upload unsuccessful, please try again</font>';
  45. $error++;
  46. }
  47. }
  48. }
  49. }
  50. if ($error > 0) {
  51. echo $result;
  52. }
  53. else {
  54. $con = mysql_connect('localhost',$username,$password);
  55. @mysql_select_db($database) or die( "Unable to select database");
  56. $sql = "INSERT INTO `tutorials` VALUES ('','$tut_name','$tut_link','$tut_program','$tut_category','$tut_video','$tut_download','$imageName')";
  57. $query = mysql_query($sql) or die('Error: ' . mysql_error());
  58. }
  59.  
  60. mysql_close();
  61.  
  62. ?>
Last edited by kkeith29; Mar 7th, 2008 at 8:57 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 52
Reputation: Scottmandoo is an unknown quantity at this point 
Solved Threads: 0
Scottmandoo's Avatar
Scottmandoo Scottmandoo is offline Offline
Junior Poster in Training

Re: Upload images to a folder script problem

 
0
  #5
Mar 9th, 2008
Thanks kkiehth29, but again another problem, heres what I get.

Error: Column count doesn't match value count at row 1
Edit: nvm it works now, thanks a lot
Last edited by Scottmandoo; Mar 9th, 2008 at 5:06 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC