Hi Guys. I have a bit code I use pretty much all the time to upload images for me, but for some reason it’s not working for me today and it has been driving me insane for the last 3 hours trying to figure it out. Could someone help me please.
Here is most of the code for the page:
<?php
#########################################
#########################################
#########################################
#########################################
//define a maxim size for the uploaded images in Kb
define ("MAX_SIZE","100");
//This function reads the extension of the file. It is used to determine if the file is an image by checking the extension.
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
//This variable is used as a flag. The value is initialized with 0 (meaning no error found)
//and it will be changed to 1 if an errro occures.
//If the error occures the file will not be uploaded.
$errors=0;
//checks if the form has been submitted
if(isset($_POST['Submit']))
{
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
//if it is not empty
if ($image)
{
//get the original name of the file from the clients machine
$filename = stripslashes($_FILES['image']['name']);
//get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
//if it is not a known extension, we will suppose it is an error and will not upload the file,
//otherwise we will do more tests
if (($extension != "jpg") && ($extension != "jpeg"))
{
//print error message
echo '<div id="site111"><h1>Unknown extension!</h1></div>';
$errors=1;
}
else
{
//get the size of the image in bytes
//$_FILES['image']['tmp_name'] is the temporary filename of the file
//in which the uploaded file was stored on the server
$size=filesize($_FILES['image']['tmp_name']);
//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*1024)
{
echo '<div id="site111"><h1>You have exceeded the size limit!</h1></div>';
$errors=1;
}
//we will give an unique name, for example the time in unix time format
//$image_name=time().'.'.$extension;
$image_name = "feature_img.jpg";
//the new name will be containing the full path where will be stored (images folder)
$newname=$row_paths['path2']."images/".$image_name;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<div id="site111"><h1>Copy unsuccessfull!</h1></div>';
$errors=1;
}}}}
//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors)
{
echo '<div id="site111"><h1>File Uploaded Successfully! Try again!</h1></div>';
}
#########################################
#########################################
#########################################
#########################################
#########################################
#########################################
#########################################
#########################################
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$colname_paths = "-1";
if (isset($_GET['id'])) {
$colname_paths = $_GET['id'];
}
mysql_select_db($database_emaildb, $emaildb);
$query_paths = sprintf("SELECT * FROM paths WHERE id = %s", GetSQLValueString($colname_paths, "int"));
$paths = mysql_query($query_paths, $emaildb) or die(mysql_error());
$row_paths = mysql_fetch_assoc($paths);
$totalRows_paths = mysql_num_rows($paths);
#########################################
#########################################
#########################################
#########################################
?>
<!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> E-Newsletter, Create Feature [Step 1 of 6].</title>
<link rel="stylesheet" type="text/css" href="sitecss.css" />
</head>
<body>
<div id="site111">
<div id="site">
<div id="title">
</div>
<br />
<br />
<br />
<h2>Main Feature</h2>
<? //create_feature.php?id=<? echo $row_paths['id']; ?>
<form name="createFeature" action="<? $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" onsubmit="" >
<label>Remaing Characters</label><input readonly type="text" name="remLen1" size="3" maxlength="3" value="18" /><br />
<label>Enter Title for Feature:</label><input type="text" name="feature_title" style="width:300px;"
onKeyDown="textCounter(document.createFeature.feature_title,document.createFeature.remLen1,18)"
onKeyUp="textCounter(document.createFeature.feature_title,document.createFeature.remLen1,18)" value="<? $feature_title ?>"/><br />
<label>Remaing Characters</label><input readonly type="text" name="remLen2" size="3" maxlength="3" value="360" /><br />
<label>Enter the Feature:</label><textarea cols="25" rows="20" name="feature" wrap="physical"
onKeyDown="textCounter(document.createFeature.feature,document.createFeature.remLen2,360)"
onKeyUp="textCounter(document.createFeature.feature,document.createFeature.remLen2,360)" value="<? $feature ?>"></textarea><br />
<label>Select the main Image:</label><input name="image" type="file" /><br />
<label>Insert Link For Feature:</label><input type="text" name="feature_link" value="<? $feature_link ?>" style="width:300px;" /><br />
<label></label><input type="Submit" value="Submit" name="Sumbit" /><input type="Reset" value="Reset" /><br />
</form>
</div>
</div>
</body>
</html>
<?php
mysql_free_result($paths);
?>
I’m sure I have the correct permissions on the folders too (I’ve tried both 777 and 744). The thing is it’s not even showing the errors i.e. ‘unsuccessful’. So it seems as if the script is not being run…argh…