PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
This very much depends on what you think constitute an item there. It could be 4 (if we considered item to be uploaded file), or 20 (if we considered item to be any 'list' item, in other words - non-array), or something completely different. What are you trying to achieve?
Weirdan wrote:This very much depends on what you think constitute an item there. It could be 4 (if we considered item to be uploaded file), or 20 (if we considered item to be any 'list' item, in other words - non-array), or something completely different. What are you trying to achieve?
# get size of the $_FILES array.
$size = count($_FILES['image']['name']);
//echo "<error message='$size'/>";
# check if it has more than zero item and it is not empty.
if($size > 0 && !empty($_FILES['image']['name'][0]))
{
include('image_upload_qna_xml.php');
}
i want to check if the $_FILES array is not zero and not empty, then start running the uploading script which is in image_upload_qna_xml.php
if (!$_FILES) {
die('nothing was uploaded');
}
if (!isset($_FILES['upload']['name']) || !is_array($_FILES['upload']['name']) {
die('something was uploaded, but not using the "upload" field');
}
foreach ($_FILES['upload']['name'] as $index => $name) {
// error codes from http://us2.php.net/manual/en/features.file-upload.errors.php
switch ($_FILES['upload']['error']) {
case UPLOAD_ERR_OK:
// process the file here
move_uploaded_file($_FILES['upload']['tmp_name'][$index], '/var/data/' . uniqid(basename($name), true));
break;
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
die('file size limit exceeded for ' . $index . ' file');
case UPLOAD_ERR_PARTIAL:
die('file ' . $index . ' was uploaded partially');
case UPLOAD_ERR_NO_FILE:
die('hmm... file ' . $index . ' was uploaded, but it wasn\'t?');
case UPLOAD_ERR_NO_TMP_DIR:
die('we have no upload dir, can\'t accept the file');
case UPLOAD_ERR_CANT_WRITE:
die('can\'t write file ' . $index . ' to disk');
case UPLOAD_ERR_EXTENSION:
die('some of php extensions stopped the file ' . $index . ' upload');
default:
die('unknown error while processing file ' . $index);
}
}
// all files have been uploaded (and moved to /var/data), continue processing