感谢您查看此内容,我收到此错误。
Warning: Invalid argument supplied for foreach() in /home/chris/public_html/marketplace/add_part.processor.php on line 45
Fatal error: Call to undefined function error() in /home/chris/public_html/marketplace/add_part.processor.php on line 55
是我的代码。
<?php
// filename: upload.processor.php
// first let's set some variables
// make a note of the current working directory, relative to root.
$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
// make a note of the directory that will recieve the uploaded files
$uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploaded_files/';
$uploadsDirectoryThumb = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploaded_file_thumbs/';
// make a note of the location of the upload form in case we need it
$uploadForm = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'multiple.upload.form.php';
// make a note of the location of the success page
$uploadSuccess = 'parts.php';
// name of the fieldname used for the file in the HTML form
$fieldname = 'file';
//echo'<pre>';print_r($_FILES);exit;
// Now let's deal with the uploaded files
// possible PHP upload errors
$errors = array(1 => 'php.ini max file size exceeded',
2 => 'html form max file size exceeded',
3 => 'file upload was only partial',
4 => 'no file was attached',
5 => 'unable to resize image',
6 => 'error uploading to database');
// check the upload form was actually submitted else print form
isset($_POST['submit'])
or error('the upload form is neaded', $uploadForm);
// check if any files were uploaded and if
// so store the active $_FILES array keys
$active_keys = array();
foreach($_FILES[$fieldname]['name'] as $key => $filename)
{
if(!empty($filename))
{
$active_keys[] = $key;
}
}
// check at least one file was uploaded
count($active_keys)
or error('No files were uploaded', $uploadForm);
// check for standard uploading errors
foreach($active_keys as $key)
{
($_FILES[$fieldname]['error'][$key] == 0)
or error($_FILES[$fieldname]['tmp_name'][$key].': '.$errors[$_FILES[$fieldname]['error'][$key]], $uploadForm);
}
// check that the file we are working on really was an HTTP upload
foreach($active_keys as $key)
{
@is_uploaded_file($_FILES[$fieldname]['tmp_name'][$key])
or error($_FILES[$fieldname]['tmp_name'][$key].' not an HTTP upload', $uploadForm);
}
// validation... since this is an image upload script we
// should run a check to make sure the upload is an image
foreach($active_keys as $key)
{
@getimagesize($_FILES[$fieldname]['tmp_name'][$key])
or error($_FILES[$fieldname]['tmp_name'][$key].' not an image', $uploadForm);
}
// make a unique filename for the uploaded file and check it is
// not taken... if it is keep trying until we find a vacant one
foreach($active_keys as $key)
{
$now = time();
while(file_exists($uploadFilename[$key] = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name'][$key]))
{
$now++;
}
}
// now let's move the file to its final and allocate it with the new filename
foreach($active_keys as $key)
{
@move_uploaded_file($_FILES[$fieldname]['tmp_name'][$key], $uploadFilename[$key])
or error('receiving directory insuffiecient permission', $uploadForm);
}
function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth, $quality){
$details = getimagesize("$imageDirectory/$imageName") or die('Please only upload images.');
$type = preg_replace('@^.+(?<=/)(.+)$@', '$1', $details['mime']);
eval('$srcImg = imagecreatefrom'.$type.'("$imageDirectory/$imageName");');
$thumbHeight = $details[1] * ($thumbWidth / $details[0]);
$thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight,
$details[0], $details[1]);
eval('image'.$type.'($thumbImg, "$thumbDirectory/$imageName"'.
(($type=='jpeg')?', $quality':'').');');
imagedestroy($srcImg);
imagedestroy($thumbImg);
}
foreach($active_keys as $key)
{
$tmp_name = $_FILES[$fieldname]["tmp_name"][$key];
$name = $now.'-'.$_FILES[$fieldname]["name"][$key];
move_uploaded_file($tmp_name, "data/$name");
createThumbnail($uploadsDirectory, $name, $uploadsDirectoryThumb, 120, 80);
//120 = thumb width :: 80 = thumb quality (1-100)
}
$cat_id = $_POST['cat_id'];
$part_name = $_POST['part_name'];
$part_qty = $_POST['part_qty'];
$part_price = $_POST['part_price'];
$main_img = $now.'-'.$_FILES[$fieldname]["name"][0];
$part_desc = $_POST['part_desc'];
$extra_1 = $now.'-'.$_FILES[$fieldname]["name"][1];
$extra_2 = $now.'-'.$_FILES[$fieldname]["name"][2];
$extra_3 = $now.'-'.$_FILES[$fieldname]["name"][3];
$extra_4 = $now.'-'.$_FILES[$fieldname]["name"][4];
$part_loc = $_POST['part_loc'];
$user_id = $_POST['user_id'];
$date = date("m/d/Y");
mysql_connect(localhost, chris_buyandsell, buyandsell);
mysql_select_db('chris_buyandsell');
$query = "INSERT INTO part (part_name,part_img_main,part_img_more_1,part_img_more_2,part_img_more_3,part_img_more_4,part_cat,part_qty,part_price,part_desc,part_loc,user_id,date_added)";
$query .= " VALUES ('$part_name','$main_img','$extra_1','$extra_2','$extra_3','$extra_4','$cat_id','$part_qty','$part_price','$part_desc','$part_loc','$user_id','$date')";
$result = mysql_query($query) or die(mysql_error());
// If you got this far, everything has worked and the file has been successfully saved.
// We are now going to redirect the client to the success page.
//header('Location: ' . $uploadSuccess);
?>
它是图像的巨大上传脚本,并将它们插入数据库。 我的所有文件字段都有正确的名称,分配为 name =“file []”,我不确定为什么它不起作用。
答案 0 :(得分:0)
找不到error()函数,因此请链接功能控制器或纠正错误功能,这样可以解决您的问题。
public funtion error($data1, $data2)
{
echo "there was a error\n";
var_dump($data1);
echo "<br />";
var_dump($data2);
}