Хорошо, у меня возникли проблемы с загрузкой и просмотром изображения, которое я пытаюсь использовать в качестве "изображения профиля". Когда я загружаю изображение, я не получаю никаких ошибок или чего-либо еще, но когда я попал на страницу сведений, чтобы увидеть, есть ли она,там ничего нет, phpmyadmin меняет imagedata для BLOB-NULL на BLOB-0B, поэтому что-то происходит, но все остальные атрибуты пусты, т.е.имя изображения, тип изображения, размер изображения.Без публикации всего моего кода, потому что его довольно много, у кого-нибудь есть идеи, что это может быть?
РЕДАКТИРОВАТЬ С КОДОМ:
html для добавления:
<tr><td>Profile Picture:</td> <td><input type="hidden" value="1000000" name="MAX_FILE_SIZE">
<input type="file" size="30" value="Image file" name="imagefile"></td></tr>
php для добавления:
$profilepic = $_FILES['imagefile'];
$personid = add_person($username, $firstname, $lastname, $profilepic...etc);
отображение изображения:
<img src="get_image.php?id={$person.id}" {$person.imagesize} alt="{$person.imagename}">
в моем add_person у меня есть:
$image_details = process_uploaded_image_file($profilepic);
list($imagedata, $imagename, $imagetype, $imagewidthheight) = $image_details;
then i insert those into my database
и, наконец, мой get_image.php
$id = $_GET['id'];
$image = getImage($id);
$data = $image['imagedata'];
$name = $image['imagename'];
$type = $image['imagetype'];
$size = strlen($data);
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
echo $data;
вот и все, что я могу опубликовать без функции образа процесса, изменения размера и т. Д.
РЕДАКТИРОВАТЬ С process_ipload_image_file:
function process_uploaded_image_file($image) {
// Check upload succeeded
if (!is_uploaded_file($image['tmp_name']) || $image['size'] == 0) {
return NULL;
}
// Extract details
$imagedata = addslashes(file_get_contents($image['tmp_name']));
$imagename = addslashes(basename($image['name']));
$imagesize = getimagesize($image['tmp_name']); // an array
$imagewidthheight = addslashes($imagesize[3]);
$imagetype = $imagesize['mime'];
// Check file is a JPEG
if ($imagetype != "image/jpeg") {
return NULL;
}
/*
echo "Before resizing: name = $imagename, type = $imagetype, ",
"size = '$imagewidthheight'<br>\n";
*/
// Resize uploaded JPEG file, if necessary
// (shouldn't reuse name tmp.jpg repeatedly)
if ($imagesize[0] > MAX_WIDTH || $imagesize[1] > MAX_HEIGHT) {
resize_image_file($image['tmp_name'], "images/tmp.jpg",
MAX_WIDTH, MAX_HEIGHT);
list($width,$height) = getimagesize("images/tmp.jpg");
$imagedata = addslashes(file_get_contents("images/tmp.jpg"));
$imagewidthheight = "width=\"$width\" height=\"$height\"";
}
/*
echo "After resizing: name = $imagename, type = $imagetype, ",
"size = '$imagewidthheight'<br>\n";
*/
return array($imagedata, $imagename, $imagetype, $imagewidthheight);
}
Вот функция изменения размера
/* Resize image into a width-height rectangle using GD library. */
function resize_image_file($src_file, $dst_file, $width, $height) {
// Compute new dimensions
list($width_orig, $height_orig) = getimagesize($src_file);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}
// Resample $srcfile
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($src_file);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output resized image to $dst_file
imagejpeg($image_p, "$dst_file", 100);
}