Hola. Estoy intentando acoplar esto en mi site pero tengo algunas dudas.
El codigo que estoy utilizando es
este. Subiendo estos ficheros al servidor funciona pero solo en IE y no en Firefox (Cuando en la web de
Swfupload si que funciona.
link)
Lo que quiero hacer es que me suba un conjunto de imágenes para que después meterlas en BD para crear una galería pero no se que código meter en PHP para que realice esa tarea.
Los códigos son los siguientes:
index.php Código HTML:
<?php
session_start();
$_SESSION["file_info"] = array();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>SWFUpload Demos - Application Demo</title>
<link href="css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="swfupload/swfupload.js"></script>
<script type="text/javascript" src="js/handlers.js"></script>
<script type="text/javascript">
var swfu;
window.onload = function () {
swfu = new SWFUpload({
// Backend Settings
upload_url: "upload.php", // Relative to the SWF file
post_params: {"PHPSESSID": "<?php echo session_id(); ?>"},
// File Upload Settings
file_size_limit : "2048", // 2MB
file_types : "*.jpg",
file_types_description : "JPG Images",
file_upload_limit : "0",
// Event Handler Settings - these functions as defined in Handlers.js
// The handlers are not part of SWFUpload but are part of my website and control how
// my website reacts to the SWFUpload events.
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,
// Flash Settings
flash_url : "swfupload/swfupload_f9.swf", // Relative to this file
custom_settings : {
upload_target : "divFileProgressContainer"
},
// Debug Settings
debug: false
});
};
</script>
</head>
<body>
<div id="header">
<h1 id="logo"><a href="../">SWFUpload</a></h1>
<div id="version">v2.1.0</div>
</div>
<div id="content">
<h2>Application Demo</h2>
<p>This demo shows how SWFUpload can behave like an AJAX application. Images are uploaded by SWFUpload then some JavaScript is used to display the thumbnails without reloading the page.</p>
<?php
if( !function_exists("imagecopyresampled") ){
?>
<div class="message">
<h4><strong>Error:</strong> </h4>
<p>Application Demo requires GD Library to be installed on your system.</p>
<p>Usually you only have to uncomment <code>;extension=php_gd2.dll</code> by removing the semicolon <code>extension=php_gd2.dll</code> and making sure your extension_dir is pointing in the right place. <code>extension_dir = "c:\php\extensions"</code> in your php.ini file. For further reading please consult the <a href="http://ca3.php.net/manual/en/image.setup.php">PHP manual</a></p>
</div>
<?php
} else {
?>
<form>
<button id="btnBrowse" type="button" style="padding: 5px;" onclick="swfu.selectFiles(); this.blur();"><img src="http://www.forosdelweb.com/images/page_white_add.png" style="padding-right: 3px; vertical-align: bottom;">Select Images <span style="font-size: 7pt;">(2 MB Max)</span></button>
</form>
<?php
}
?>
<div id="divFileProgressContainer" style="height: 75px;"></div>
<div id="thumbnails"></div>
</div>
</body>
</html>
upload.php Código PHP:
<?php
/* Note: This thumbnail creation script requires the GD PHP Extension.
If GD is not installed correctly PHP does not render this page correctly
and SWFUpload will get "stuck" never calling uploadSuccess or uploadError
*/
// Get the session Id passed from SWFUpload. We have to do this to work-around the Flash Player Cookie Bug
if (isset($_POST["PHPSESSID"])) {
session_id($_POST["PHPSESSID"]);
}
session_start();
// Check the upload
if (!isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) {
header("HTTP/1.1 500 Internal Server Error");
echo "invalid upload";
exit(0);
}
// Get the image and create a thumbnail
$img = @imagecreatefromjpeg($_FILES["Filedata"]["tmp_name"]);
if (!$img) {
header("HTTP/1.1 500 Internal Server Error");
echo "could not create image handle";
exit(0);
}
$width = imageSX($img);
$height = imageSY($img);
if (!$width || !$height) {
header("HTTP/1.1 500 Internal Server Error");
echo "Invalid width or height";
exit(0);
}
// Build the thumbnail
$target_width = 100;
$target_height = 100;
$target_ratio = $target_width / $target_height;
$img_ratio = $width / $height;
if ($target_ratio > $img_ratio) {
$new_height = $target_height;
$new_width = $img_ratio * $target_height;
} else {
$new_height = $target_width / $img_ratio;
$new_width = $target_width;
}
if ($new_height > $target_height) {
$new_height = $target_height;
}
if ($new_width > $target_width) {
$new_height = $target_width;
}
$new_img = ImageCreateTrueColor(100, 100);
if (!@imagefilledrectangle($new_img, 0, 0, $target_width-1, $target_height-1, 0)) { // Fill the image black
header("HTTP/1.1 500 Internal Server Error");
echo "Could not fill new image";
exit(0);
}
if (!@imagecopyresampled($new_img, $img, ($target_width-$new_width)/2, ($target_height-$new_height)/2, 0, 0, $new_width, $new_height, $width, $height)) {
header("HTTP/1.0 500 Internal Server Error");
echo "Could not resize image";
exit(0);
}
if (!isset($_SESSION["file_info"])) {
$_SESSION["file_info"] = array();
}
// Use a output buffering to load the image into a variable
ob_start();
imagejpeg($new_img);
$imagevariable = ob_get_contents();
ob_end_clean();
$file_id = md5($_FILES["Filedata"]["tmp_name"] + rand()*100000);
$_SESSION["file_info"][$file_id] = $imagevariable;
echo $file_id; // Return the file id to the script
?>
Agradeceria un moton vuestra ayuda.
Un saludo y gracias.