Reputation: 159
I've been making an image uploader and I'm having a couple of issues.
Code is so simple: it gets a file (zip file) froom a form and a couple of info text, then generates an url if it isn't exists previously and then extracts the file there.
First one is, that the form variables ($_post["serie"]
and $_POST["capitulo"]
seems to expire if the file is large and take some time to upload.
Second one is that it tends to fail when uploading not jpg stuff >< and don't know why.
Thanks for your efforts in advance.
<?php
require_once('pclzip.lib.php');
function preextract($p_event, &$p_header) {
$info = pathinfo($p_header['filename']);
if ($info['extension'] == 'gif' || $info['extension'] == 'jpg' || $info['extension'] == 'png' || $info['extension'] == 'jpeg') {
return 1;
} else {
return 0;
}
}
if(is_uploaded_file($_FILES['file']['tmp_name'])) {
echo $_FILES['file']['tmp_name'];
}
$archive = new PclZip($_FILES['file']['tmp_name']);
$extractpath = "../series/" . $_POST["serie"] . "/" . $_POST["capitulo"];
echo $extractpath;
if (file_exists($extractpath)) {
} else {
mkdir($extractpath, 0755);
}
if (($archive->extract(PCLZIP_OPT_PATH, $extractpath, PCLZIP_CB_PRE_EXTRACT, 'preextract') == 0)) {
echo "\n error in extraction";
} else {
echo "\n done";
}
?>
Upvotes: 2
Views: 157
Reputation: 13517
A few things...
You need to increase the max filesize to submit larger files:
ini_set( 'upload_max_filesize', '100M' );
ini_set( 'post_max_size', '100M' );
Change your file_exists
check:
if ( !file_exists( $extractpath ) )
mkdir( $extractpath, 0755 );
Change your extension check:
return in_array( $info['extension'], array( 'png', 'jpg', 'jpeg', 'gif' ) ) ? 1 : 0;
I'm not sure why it only works on one extension, maybe PclZip
has a setting prohibiting certain files, so look for that.
Upvotes: 2