Using some standard Upload code.
The user was able to upload one image. But, when the user attempts to upload a second image, an error appears: "-1 Something barfed, check the path to and the permissions for the upload directory."
The path seems to be correct. It should be going to "../Images/Exhibitions/{exhibition title}"
Perhaps I'm not chmod'ing the directory correctly? Setting it to 755.
Kinda desperate to get this fixed, as we're on a production schedule.
Here is the actual code (username, password and database x'd out for security):
<?
include("../Include/SSI/constants.php");
mysql_connect($dbHostAndSocket, $dbUserName, $dbPassword)
or die("couldn't find mysql server");
@mysql_select_db($schema) ;
$artistSQL = "SELECT * FROM artists";
$artistResult = mysql_query($artistSQL);
$count = 0;
?>
<? include($header); ?>
<body id="exhibitions2">
<div id="main_navigation2">
<? include($navigation2); ?>
</div>
<div id="everything_else" style="overflow: auto;">
<div id="section_navigation">
<img src="../Images/SectionTitle.Header.Exhibitions.Default.gif" />
</div>
<?
$id1=$_GET['id'];
$username="xxxxxxxxx";
$password="xxxxxx";
$database="xxxxxxx";
mysql_connect("db418.perfora.net",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM `exhibits` ORDER BY id ASC;";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
?>
<table id="section_content">
<?
$i=0;
while ($i < $num) {
$id=mysql_result($result, $i,"id");
$location=mysql_result($result, $i,"location");
$title=mysql_result($result, $i,"title");
$dates=mysql_result($result, $i,"dates");
$artists=mysql_result($result, $i,"artists");
$status=mysql_result($result, $i,"status");
$release=mysql_result($result, $i,"release");
$flip=mysql_result($result, $i,"flip");
if ($id1 == $id)
{
echo '<tr><td colspan="2"></td></tr>';
$id2=$id;
$title2=$title;
}
if ($id2 == $id)
{
$id2=$id;
$title2=$title;
}
$i++;
}
echo '<tr><td colspan="2">';
$my_max_file_size = "60000000"; # in bytes
$image_max_width = "800";
$image_max_height = "800";
$the_path = "../Images/Exhibitions/";
$the_path .= $title2;
$registered_types = array(
"application/x-gzip-compressed" => ".tar.gz, .tgz",
"audio/mpeg" => ".mp3",
"application/x-zip-compressed" => ".zip",
"application/x-tar" => ".tar",
"text/plain" => ".html, .php, .txt, .inc (etc)",
"image/bmp" => ".bmp, .ico",
"image/gif" => ".gif",
"image/pjpeg" => ".jpg, .jpeg",
"image/jpeg" => ".jpg, .jpeg",
"application/x-shockwave-flash" => ".swf",
"application/msword" => ".doc",
"application/vnd.ms-excel" => ".xls",
"application/octet-stream" => ".exe, .fla (etc)"
); # these are only a few examples, you can find many more!
$allowed_types = array("audio/mpeg","image/gif","image/pjpeg","image/jpeg");
# --
function form($error=false) {
global $PHP_SELF,$my_max_file_size,$id2;
if ($error) print $error . "<br><br>";
print "\n<form ENCTYPE=\"multipart/form-data\" action=\"" . $PHP_SELF . "\" method=\"post\">";
print "\n<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"" . $my_max_file_size . "\">";
print "\n<INPUT TYPE=\"hidden\" name=\"task\" value=\"upload\">";
print "\n<INPUT TYPE=\"hidden\" name=\"id2\" value=\"" .$id2 . "\">";
print "\n<INPUT TYPE=\"hidden\" name=\"title2\" value=\"" .$title2 . "\">";
print "\n<P>Upload image";
print "\n<BR>NOTE: Max image size is " . ($my_max_file_size / 1024) . "KB";
print "\n<br><INPUT NAME=\"the_file\" TYPE=\"file\" SIZE=\"35\"><br>";
print "\n<input type=\"image\" src=\"../Images/Upload.jpg\" Value=\"Upload\">";
print "\n</form>";
} # END form
# --
if (!ereg("^4",phpversion())) {
function in_array($needle,$haystack) { # we have this function in PHP4, so for you PHP3 people
for ($i=0; $i < count($haystack); $i++) {
if ($haystack[$i] == $needle) {
return true;
}
}
}
}
# --
function validate_upload($the_file) {
global $my_max_file_size, $image_max_width, $image_max_height,$allowed_types,$the_file_type,$registered_types;
$start_error = "\n<b>Error:</b>\n<ul>";
if ($the_file == "none") { # do we even have a file?
$error .= "\n<li>You did not upload anything!</li>";
} else { # check if we are allowed to upload this file_type
if (!in_array($the_file_type,$allowed_types)) {
$error .= "\n<li>The file that you uploaded was of a type that is not allowed, you are only
allowed to upload files of the type:\n<ul>";
while ($type = current($allowed_types)) {
$error .= "\n<li>" . $registered_types[$type] . " (" . $type . ")</li>";
next($allowed_types);
}
$error .= "\n</ul>";
}
if (ereg("image",$the_file_type) && (in_array($the_file_type,$allowed_types))) {
$size = GetImageSize($the_file);
list($foo,$width,$bar,$height) = explode("\"",$size[3]);
if ($width > $image_max_width) {
$error .= "\n<li>Your image should be no wider than " . $image_max_width . " Pixels</li>";
}
if ($height > $image_max_height) {
$error .= "\n<li>Your image should be no higher than " . $image_max_height . " Pixels</li>";
}
}
if ($error) {
$error = $start_error . $error . "\n</ul>";
return $error;
} else {
return false;
}
}
} # END validate_upload
# --
function list_files() {
global $the_path,$id2,$title2;
$handle = opendir($the_path);
print "\n Images uploaded.<br><b><u>" . $title2 . "</u> image files:</b><br><br>";
print "\n<table>";
while ($file = readdir($handle)){
if (($file != ".") && ($file != "..")) {
print "\n<tr><td width=100>" . $file . "</td><td width=200 align=center><img height=100 width=100 src=\"../Images/Exhibitions/" . $title2 . "/" . $file . "\"></td><td><a href=\"deleximage.php?title=" . $title2 . "&file=" . $file . "\"><img src=\"../Images/Delete.jpg\" border=\"0\"></a></tr>";
}
}
print "</table><br><b></b><hr>";
}
# --
function upload($the_file) {
global $the_path,$the_file_name,$id2;
$handle = OPENDIR($the_path);
$count = 0;
IF (is_file($file) && $file !== '.' && $file !== '..')
{
$count++;
}
$count = $count - 1;
WHILE (false !== ($file = readdir($handle)))
{
$count++;
}
echo $count;
$error = validate_upload($the_file);
if ($error) {
form($error);
} else { # cool, we can continue
if (!@copy($the_file, $the_path . "/" . $the_file_name)) {
form("\n<b>Something barfed, check the path to and the permissions for the upload directory</b>");
} else {
rename($the_path . "/" . $the_file_name, $the_path . "/" . "Artwork.CurrentEx.Flipper." . $count . ".jpg");
list_files();
form();
}
}
} # END upload
# --
############ Start page
switch($task) {
case 'upload':
upload($the_file);
break;
default:
list_files();
form();
}
?>
</td></tr>
<tr><td align="center" colspan="2">
<a href="index.php">
<img src="../Images/Back.jpg" border="0"></a></td></tr>
</table>
</td></tr>
</table>
</p>
</div>
<? include($footer); ?>
</body>
</html>