...

View Full Version : Uploading & Temp Files



Raraken
02-09-2006, 10:23 PM
I've been working on a content managment system for online comics, and I've been using the same file-uploading function the entire time from when I wrote it.

However, it has all of a sudden stopped working, all I get is this error (or a similar one) whenever I try to run an upload:


Warning: move_uploaded_file(/home/raraken/domains/manager.hypercomix.net/public_html/image_bin/thumbs/X_1_5dab081aacdb_quickpixel_1p(002).gif): failed to open stream: No such file or directory in /home/raraken/domains/manager.hypercomix.net/public_html/demo/cpanel/cpl_functions.php on line 271

Warning: move_uploaded_file(): Unable to move '/tmp/phpJNa7WY' to '/home/raraken/domains/manager.hypercomix.net/public_html/image_bin/thumbs/X_1_5dab081aacdb_quickpixel_1p(002).gif' in /home/raraken/domains/manager.hypercomix.net/public_html/demo/cpanel/cpl_functions.php on line 271

There are 3 functions, and none of them seem to be working, so I'm going to post them all...

Basic file uploads (single file to a pre-determined destination)

// ----------------------------------------------------------------------
//
// File Uploads
//
// ----------------------------------------------------------------------
function upload_file ($file,$target,$randit = false) {
global $logged_ID, $config;

// Set variables
$file_name = $_FILES[$file]['name'];
$file_type = $_FILES[$file]['type'];
$file_temp = $_FILES[$file]['tmp_name'];
$file_targ = $_SERVER['DOCUMENT_ROOT'].'/'.$config['file_root'].$target;
$use_file = false;

// Find and detect file type
$query = "SELECT * FROM ".SQL_FILETYPES;
$result = mysql_query($query) or die(mysql_die_message());
while ($format = mysql_fetch_assoc($result)) {
if ($file_type == $format['format_type']) {
$use_file = true;
break;
}
}
$use_file = true;
if ($randit == true) {
$file_rand = '_'.substr(md5(rand()),rand(0,20),12);
} else {
$file_rand = '';
}
if (isset($logged_ID)) {
$file_user = $logged_ID;
} else {
$file_user = 'X';
}

// Upload the file
if ($use_file == true && $file_temp != "") {
$file_call = $file_user."_".($config['total_thumbs']+1).$file_rand.'_'.basename($file_name);
$file_cplt = $file_targ.$file_call;
if (!move_uploaded_file($file_temp, $file_cplt)) {
return(false);
} else {
$new_name = $httpbase.$file_call;
}
} else {
return(false);
}

$query = "INSERT INTO `".SQL_FILES."` (`file_name`,`file_short`,`file_type`)";
$query .= "VALUES ('".modstring_sqlsafe($target.$new_name)."','".modstring_sqlsafe($new_name)."','".modstring_sqlsafe($file_type)."');";
mysql_query($query) or die(mysql_die_message());

$query = "SELECT * FROM ".SQL_FILES." ORDER BY -file_id LIMIT 1";
$result = mysql_query($query) or die(mysql_die_message());
$file_id = mysql_fetch_assoc($result);
return($file_id['file_id']);
}


Multiple images at once (via arrays)

// ----------------------------------------------------------------------
//
// File Array Uploads
//
// ----------------------------------------------------------------------
function upload_array ($file,$target,$randit = false) {
global $logged_ID, $config;
$file_array = array();
foreach ($_FILES[$file]['name'] as $cf => $file_toss) {
// Set variables
$file_name = $_FILES[$file]['name'][$cf];
$file_type = $_FILES[$file]['type'][$cf];
$file_temp = $_FILES[$file]['tmp_name'][$cf];
$file_targ = $_SERVER['DOCUMENT_ROOT'].'/'.$config['file_root'].$target;
$use_file = false;

// Find and detect file type
$query = "SELECT * FROM ".SQL_FILETYPES;
$result = mysql_query($query) or die(mysql_die_message());
while ($format = mysql_fetch_assoc($result)) {
if ($file_type == $format['format_type']) {
$use_file = true;
break;
}
}
$use_file = true;
if ($randit == true) {
$file_rand = '_'.substr(md5(rand()),rand(0,20),12);
} else {
$file_rand = '';
}
if (isset($logged_ID)) {
$file_user = $logged_ID;
} else {
$file_user = 'X';
}

// Upload the file
if ($use_file == true && $file_temp != "") {
$file_call = $file_user."_".($config['total_files']+1).$file_rand.'_'.basename($file_name);
$file_cplt = $file_targ.$file_call;
if (!move_uploaded_file($file_temp, $file_cplt)) {
return(false);
} else {
$new_name = $httpbase.$file_call;
}
} else {
return(false);
}

$query = "INSERT INTO `".SQL_FILES."` (`file_name`,`file_short`,`file_type`)";
$query .= "VALUES ('".modstring_sqlsafe($target.$new_name)."','".modstring_sqlsafe($new_name)."','".modstring_sqlsafe($file_type)."');";
mysql_query($query) or die(mysql_die_message());
$query = "SELECT * FROM ".SQL_FILES." ORDER BY -file_id LIMIT 1";
$result = mysql_query($query) or die(mysql_die_message());
$file_id = mysql_fetch_assoc($result);

$file_array[] = $file_id['file_id'];
}
return($file_array);
}


And lastly, "Thumbnail Uploads" (Exactly the same as file uploads)


// ----------------------------------------------------------------------
//
// File Uploads (thumbnails)
//
// ----------------------------------------------------------------------
function upload_thumb ($file,$target,$randit = false) {
global $logged_ID, $config;

// Set variables
$file_name = $_FILES[$file]['name'];
$file_type = $_FILES[$file]['type'];
$file_temp = $_FILES[$file]['tmp_name'];
$file_targ = $_SERVER['DOCUMENT_ROOT'].'/'.$config['file_root'].$target;
$use_file = false;

// Find and detect file type
$query = "SELECT * FROM ".SQL_FILETYPES;
$result = mysql_query($query) or die(mysql_die_message());
while ($format = mysql_fetch_assoc($result)) {
if ($file_type == $format['format_type']) {
$use_file = true;
break;
}
}
$use_file = true;
if ($randit == true) {
$file_rand = '_'.substr(md5(rand()),rand(0,20),12);
} else {
$file_rand = '';
}
if (isset($logged_ID)) {
$file_user = $logged_ID;
} else {
$file_user = 'X';
}

// Upload the file
if ($use_file == true && $file_temp != "") {
$file_call = $file_user."_".($config['total_thumbs']+1).$file_rand.'_'.basename($file_name);
$file_cplt = $file_targ.$file_call;
if (!move_uploaded_file($file_temp, $file_cplt)) {
return(false);
} else {
$new_name = $httpbase.$file_call;
}
} else {
return(false);
}

$query = "INSERT INTO `".SQL_FILES."` (`file_name`,`file_short`,`file_type`,`file_thumb`)";
$query .= "VALUES ('".modstring_sqlsafe($target.$new_name)."','".modstring_sqlsafe($new_name)."','".modstring_sqlsafe($file_type)."','1');";
mysql_query($query) or die(mysql_die_message());

$query = "SELECT * FROM ".SQL_FILES." ORDER BY -file_id LIMIT 1";
$result = mysql_query($query) or die(mysql_die_message());
$file_id = mysql_fetch_assoc($result);
return($file_id['file_id']);
}


I know this is a lot, but thank you for any help...:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum