| | |
Upload images to a folder script problem
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
Alright this is my code, the error im getting is in red
I have also CHMODed my file destination to 777 permision
<?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
•
•
Join Date: Nov 2007
Posts: 121
Reputation:
Solved Threads: 16
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
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
try this:
PHP Syntax (Toggle Plain Text)
<?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']; $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(); ?>
Last edited by kkeith29; Mar 7th, 2008 at 8:57 pm.
![]() |
Similar Threads
- Please help file name and folder name it doesn't array A-Z,0-9 (PHP)
- Problems using a php generator (PHP)
- Programming Sag Really Need Help / Advice (ASP.NET)
Other Threads in the PHP Forum
- Previous Thread: Forwarding a web page to a friend's e-mail
- Next Thread: When i log on to my site and click a link in it. It is logging out automatically
| Thread Tools | Search this Thread |
ajax apache api array back basic beginner binary broken cakephp checkbox class cms code computing cron curl database date delete display dynamic echo email error external file files filter folder form forms function functions gc_maxlifetime google host href htaccess html iframe image include insert integration ip java javascript joomla limit link login loop mail memmory memory menu mlm multiple mysql navigation oop parsing paypal pdf php problem query question radio random recursion regex remote script search server sessions sms snippet soap source space sql syntax system table thesishelp trouble tutorial update upload url validation validator variable video web xml youtube






