andu
Fri 26 May 2006, 08:17 pm GMT +0200
First of wanted to say that you have created a great product.
I am having some problems with the image resizing feature (foto_upload.php). Evevry time i upload a file it says that uploaded and processed. But i dont see the file(s) in my directory. Interesting thing is when i upload really small images like 150x100 it uploads. But as soon as i use bigger images nothing happens. Can you please help me?
Thanks!!
Nikolas
Fri 26 May 2006, 08:21 pm GMT +0200
I am not familliar with Olaf's classes, but this could be a problem of your php.ini (max_post_size)
andu
Fri 26 May 2006, 08:25 pm GMT +0200
Nikolas,
The max size in my php.ini is upto 4MB. And in any case, it should still throw me an error of "The uploaded file exceeds the max. upload filesize directive in the server configuration."
My files ar all around 1MB.
olaf
Fri 26 May 2006, 09:11 pm GMT +0200
Nikolas,
The max size in my php.ini is upto 4MB. And in any case, it should still throw me an error of "The uploaded file exceeds the max. upload filesize directive in the server configuration."
My files ar all around 1MB.
hello,
do you have a link to the upload form you're using? and place a phpinfo file on the host where the upload doesn't work.
andu
Fri 26 May 2006, 10:07 pm GMT +0200
Hi Olaf,
I am not entirely sure what you mean but I am just using this to repost to the same page.
<form enctype="multipart/form-data" method="post" action='.$_SERVER["PHP_SELF"];echo '?id='.$id; ...................
Let me know if you wanted to know something else.
olaf
Fri 26 May 2006, 10:42 pm GMT +0200
I need to see the whole form and your php cofiguration...
andu
Fri 26 May 2006, 10:55 pm GMT +0200
Ok..heres the code...the top portion is all your code...except where i change the file paths. let me know if any Q's:
<?php //require_once ('../includes/config.inc') ?>
<?php require_once ("../../mysql_connect.php") ?>
<?php include ("../includes/customer_header.html") ?>
<?php include ("../includes/upload_class.php") ?>
<?php if(isset($_SESSION["username"]))
{
// Check for a valid user ID, through GET or POST.
if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { // Accessed through view_users.php
$id = $_GET['id'];
} elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { // Form has been submitted.
$id = $_POST['id'];
} else { // No valid ID, kill the script.
echo '<h1 id="mainhead">Page Error</h1>
<p class="error">This page has been accessed in error.</p><p><br /><br /></p>';
include ('../includes/customer_footer.html');
exit();
}
error_reporting(E_ALL);
ini_set("memory_limit", "64M");
set_time_limit(60);
class Foto_upload extends file_upload {
var $x_size;
var $y_size;
var $x_max_size = 300;
var $y_max_size = 200;
var $x_max_thumb_size = 110;
var $y_max_thumb_size = 88;
var $thumb_folder;
var $foto_folder;
var $larger_dim;
var $larger_curr_value;
var $larger_dim_value;
var $larger_dim_thumb_value;
var $use_image_magick = true; // switch between true and false
// I suggest to use ImageMagick on Linux/UNIX systems, it works on windows too, but it's hard to configurate
// check your existing configuration by your web hosting provider
function process_image($landscape_only = false, $create_thumb = false, $delete_tmp_file = false, $compression = 85) {
$filename = $this->upload_dir.$this->file_copy;
$this->check_dir($this->thumb_folder); // run these checks to create not existing directories
$this->check_dir($this->foto_folder); // the upload dir is created during the file upload (if not already exists)
$thumb = $this->thumb_folder.$this->file_copy;
$foto = $this->foto_folder.$this->file_copy;
if ($landscape_only) {
$this->get_img_size($filename);
if ($this->y_size > $this->x_size) {
$this->img_rotate($filename, $compression);
}
}
$this->check_dimensions($filename); // check which size is longer then the max value
if ($this->larger_curr_value > $this->larger_dim_value) {
$this->thumbs($filename, $foto, $this->larger_dim_value, $compression);
} else {
copy($filename, $foto);
}
if ($create_thumb) {
if ($this->larger_curr_value > $this->larger_dim_thumb_value) {
$this->thumbs($filename, $thumb, $this->larger_dim_thumb_value, $compression); // finally resize the image
} else {
copy($filename, $thumb);
}
}
if ($delete_tmp_file) $this->del_temp_file($filename); // note if you delete the tmp file the check if a file exists will not work
}
function get_img_size($file) {
$img_size = getimagesize($file);
$this->x_size = $img_size[0];
$this->y_size = $img_size[1];
}
function check_dimensions($filename) {
$this->get_img_size($filename);
$x_check = $this->x_size - $this->x_max_size;
$y_check = $this->y_size - $this->y_max_size;
if ($x_check < $y_check) {
$this->larger_dim = "y";
$this->larger_curr_value = $this->y_size;
$this->larger_dim_value = $this->y_max_size;
$this->larger_dim_thumb_value = $this->y_max_thumb_size;
} else {
$this->larger_dim = "x";
$this->larger_curr_value = $this->x_size;
$this->larger_dim_value = $this->x_max_size;
$this->larger_dim_thumb_value = $this->x_max_thumb_size;
}
}
function img_rotate($wr_file, $comp) {
$new_x = $this->y_size;
$new_y = $this->x_size;
if ($this->use_image_magick) {
exec(sprintf("mogrify -rotate 90 -quality %d %s", $comp, $wr_file));
} else {
$src_img = imagecreatefromjpeg($wr_file);
$rot_img = imagerotate($src_img, 90, 0);
$new_img = imagecreatetruecolor($new_x, $new_y);
imageantialias($new_img, TRUE);
imagecopyresampled($new_img, $rot_img, 0, 0, 0, 0, $new_x, $new_y, $new_x, $new_y);
imagejpeg($new_img, $this->upload_dir.$this->file_copy, $comp);
}
}
function thumbs($file_name_src, $file_name_dest, $target_size, $quality = 80) {
//print_r(func_get_args());
$size = getimagesize($file_name_src);
if ($this->larger_dim == "x") {
$w = number_format($target_size, 0, ',', '');
$h = number_format(($size[1]/$size[0])*$target_size,0,',','');
} else {
$h = number_format($target_size, 0, ',', '');
$w = number_format(($size[0]/$size[1])*$target_size,0,',','');
}
if ($this->use_image_magick) {
exec(sprintf("convert %s -resize %dx%d -quality %d %s", $file_name_src, $w, $h, $quality, $file_name_dest));
} else {
$dest = imagecreatetruecolor($w, $h);
imageantialias($dest, TRUE);
$src = imagecreatefromjpeg($file_name_src);
imagecopyresampled($dest, $src, 0, 0, 0, 0, $w, $h, $size[0], $size[1]);
imagejpeg($dest, $file_name_dest, $quality);
}
}
}
$max_size = 1024*1024; // the max. size for uploading (~1MB)
define("MAX_SIZE", $max_size);
$foto_upload = new Foto_upload;
$foto_upload->upload_dir = $_SERVER['DOCUMENT_ROOT']."/mysite/customers/uploads/"; // "files" is the folder for the uploaded files (you have to create these folder)
$foto_upload->foto_folder = $_SERVER['DOCUMENT_ROOT']."/mysite/customers/uploads/photo/";
$foto_upload->thumb_folder = $_SERVER['DOCUMENT_ROOT']."/mysite/customers/uploads/thumb/";
$foto_upload->extensions = array(".jpg"); // specify the allowed extension(s) here
$foto_upload->language = "en";
$foto_upload->x_max_size = 300;
$foto_upload->y_max_size = 200;
$foto_upload->x_max_thumb_size = 120;
$foto_upload->y_max_thumb_size = 150;
if (isset($_POST['Submit']) && $_POST['Submit'] == "Upload") {
$foto_upload->the_temp_file = $_FILES['upload']['tmp_name'];
$foto_upload->the_file = $_FILES['upload']['name'];
$foto_upload->http_error = $_FILES['upload']['error'];
$foto_upload->replace = (isset($_POST['replace'])) ? $_POST['replace'] : "n"; // because only a checked checkboxes is true
$foto_upload->do_filename_check = "n";
if ($foto_upload->upload()) {
$foto_upload->process_image(false, true, true, 80);
$foto_upload->message[] = "Processed foto: ".$foto_upload->file_copy."!"; // "file_copy is the name of the foto"
}
}
$error = $foto_upload->show_error_string();
echo ' <table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" width="370"><a href="index.php">Home</a> » <a href="view_photo_listings.php">View Photo Listings</a> » <span class="content">Add Photos</span></td>
<td valign="top">
<p align="right"><span class="content">You are logged in as: <b>'.$_SESSION["username"];
echo '</b></span></td>
</tr>
</table>
<p align="center">'. $error; echo '</p>
<div align="center">
<table border="0" width="70%" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" align="right"></td>
</tr>
</table>
</div>
<form enctype="multipart/form-data" method="post" action='.$_SERVER["PHP_SELF"];echo '?id='.$id;
echo '>
<input type="hidden" name="MAX_FILE_SIZE" value="'. $max_size;
echo' "><br>
<div align="center">
<table class="inputform" borderColor="#f0f0f0" border="1">
<div>
<label for="upload">Select a foto</label>
<input type="file" name="upload" id="upload" size="30"></div>
<div>
<label for="replace">Replace an old foto?</label>
<input type="checkbox" name="replace" value="y"></div>
<p style="margin-top:25px;text-align:center;">
<div align="center">
<table cellSpacing="0" cellPadding="0" width="70%" border="0">
<tr>
<td width="100%">
<p align="center"><BR><input type="submit" name="Submit" id="Submit" value="Upload">
</p>
</td>
</tr>
</table>
</form>
</div> ';
}
else {
header ("Location: http://" . $_SERVER['HTTP_HOST'] . "/mysite" . "/login.php");
}
?>
<?php include_once("../includes/customer_footer.html") ?>
olaf
Sat 27 May 2006, 09:46 am GMT +0200
;) that was too much...
The max filesize value in your form is 1MB (1024*1024)
teasso
Fri 2 June 2006, 03:35 pm GMT +0200
I am actually having the same problem. This script will only upload an image if it is within the specified file dimensions. For example, I set my max to:
var $x_max_size = 600;
var $y_max_size = 500;
This script only successfully uploads images smaller than that (regardless of MB size)
My understanding is that the script should resize the file and put it in the appropriate folder.
It does say that it uploaded successfully, but the file is nowhere to be found on my server.
olaf
Fri 2 June 2006, 03:42 pm GMT +0200
I am actually having the same problem. This script will only upload an image if it is within the specified file dimensions. For example, I set my max to:
var $x_max_size = 600;
var $y_max_size = 500;
This script only successfully uploads images smaller than that (regardless of MB size)
My understanding is that the script should resize the file and put it in the appropriate folder.
It does say that it uploaded successfully, but the file is nowhere to be found on my server.
The upload and the resize are two diff. things (maybe the messages are not clear)
I will check the message, try to upload a file from 800KB and tell if the work fine.
olaf
Fri 2 June 2006, 04:58 pm GMT +0200
Just checked the messages and the upload functions: everything is fine
maybe there are problems with the chmod values? it's a shared host?
teasso
Fri 2 June 2006, 06:17 pm GMT +0200
It's a dedicated host, and all upload folders are chmod 777.
I just removed the dimension checking. I just want to relay on actual filesize anyway.
Thanks
olaf
Fri 2 June 2006, 11:08 pm GMT +0200
I just want to relay on actual filesize anyway.
what do you mean with that? having max 1MB after Resize?
teasso
Fri 2 June 2006, 11:15 pm GMT +0200
Yeah, I want it to check for file size in MB, the height and width is not as important, so in "process_image" I changed:
$this->check_dimensions($filename); // check which size is longer then the max value
if ($this->larger_curr_value > $this->larger_dim_value) {
$this->thumbs($filename, $foto, $this->larger_dim_value, $compression);
} else {
copy($filename, $foto);
}
to
copy($filename, $foto);
olaf
Sat 3 June 2006, 08:45 am GMT +0200
you need only an upload functtion? check the regular example...
And don't change the source files otherwise you can't handle the updates later ;)
teasso
Sat 3 June 2006, 04:58 pm GMT +0200
ok. Thanks for being so insistant on helping me :-)
liverpoolrc
Mon 25 September 2006, 03:05 pm GMT +0200
Hi, i'm having the exact same problem as one of your notice board users Olaf but the issue was never answered -
I am having some problems with the image resizing feature (foto_upload.php). Evevry time i upload a file it says that uploaded and processed. But i dont see the file(s) in my directory. Interesting thing is when i upload really small images like 150x100 it uploads. But as soon as i use bigger images nothing happens. I've increased the the 1Mb limit on the script upload file and the above issue seems to be resolved but i never get any errors!!!! - lke i thought too that with the foto script, that the images are resized for you aswell?
PLEASEEEEEEEEEEEEEEEE Can you please help me?
Thanks!!
olaf
Mon 25 September 2006, 04:08 pm GMT +0200
Hi, i'm having the exact same problem as one of your notice board users Olaf but the issue was never answered -
I am having some problems with the image resizing feature (foto_upload.php). Evevry time i upload a file it says that uploaded and processed. But i dont see the file(s) in my directory. Interesting thing is when i upload really small images like 150x100 it uploads. But as soon as i use bigger images nothing happens. I've increased the the 1Mb limit on the script upload file and the above issue seems to be resolved but i never get any errors!!!! - lke i thought too that with the foto script, that the images are resized for you aswell?
PLEASEEEEEEEEEEEEEEEE Can you please help me?
Thanks!!
of course the question was answered (I think you have diff. problem) thread closed -->