A ver, intento hacer esto:
Archivo my_file.php:
Código PHP:
Ver original<form enctype="multipart/form-data" method="post" action="image_upload_script.php">
<input name="uploaded_file" type="file"/><br /><br />
<input type="submit" value="Upload It"/>
</form>
Archivo image_upload_script.php:
Código PHP:
Ver original<?php
// Access the $_FILES global variable for this specific file being uploaded
// and create local PHP variables from the $_FILES array of information
$fileName = $_FILES["uploaded_file"]["name"]; // The file name
$fileTmpLoc = $_FILES["uploaded_file"]["tmp_name"]; // File in the PHP tmp folder
$fileType = $_FILES["uploaded_file"]["type"]; // The type of file it is
$fileSize = $_FILES["uploaded_file"]["size"]; // File size in bytes
$fileErrorMsg = $_FILES["uploaded_file"]["error"]; // 0 for false... and 1 for true
$fileName = preg_replace('#[^a-z.0-9]#i', '', $fileName); // filter $kaboom = explode(".", $fileName); // Split file name into an array using the dot $fileExt = end($kaboom); // Now target the last array element to get the file extension
// START PHP Image Upload Error Handling -------------------------------
if (!$fileTmpLoc) { // if file not chosen
echo "ERROR: Please browse for a file before clicking the upload button.";
} else if($fileSize > 5242880) { // if file size is larger than 5 Megabytes
echo "ERROR: Your file was larger than 5 Megabytes in size.";
unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder } else if (!preg_match("/\.(gif|jpg|png)$/i", $fileName) ) { // This condition is only if you wish to allow uploading of specific file types
echo "ERROR: Your image was not .gif, .jpg, or .png.";
unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder } else if ($fileErrorMsg == 1) { // if file upload error key is equal to 1
echo "ERROR: An error occured while processing the file. Try again.";
}
// END PHP Image Upload Error Handling ---------------------------------
// Place it into your "uploads" folder mow using the move_uploaded_file() function
// Check to make sure the move result is true before continuing
if ($moveResult != true) {
echo "ERROR: File not uploaded. Try again.";
}
// Include the file that houses all of our custom image functions
include_once("ak_php_img_lib_1.0.php");
// ---------- Start Adams Universal Image Resizing Function --------
$target_file = "uploads/$fileName";
$resized_file = "uploads/resized_$fileName";
$wmax = 500;
$hmax = 500;
ak_img_resize($target_file, $resized_file, $wmax, $hmax, $fileExt);
// ----------- End Adams Universal Image Resizing Function ----------
// ---------- Start Adams Convert to JPG Function --------
$target_file = "uploads/resized_$fileName";
$new_jpg = "uploads/resized_".$kaboom[0].".jpg";
ak_img_convert_to_jpg($target_file, $new_jpg, $fileExt);
}
// ----------- End Adams Convert to JPG Function -----------
// ---------- Start Adams Image Watermark Function --------
$target_file = "uploads/resized_".$kaboom[0].".jpg";
$wtrmrk_file = "watermark.png";
$new_file = "uploads/protected_".$kaboom[0].".jpg";
ak_img_watermark($target_file, $wtrmrk_file, $new_file);
// ----------- End Adams Image Watermark Function -----------
// Display things to the page so you can see what is happening for testing purposes
echo "The file named <strong>$fileName</strong> uploaded successfuly.<br /><br />";
echo "It is <strong>$fileSize</strong> bytes in size.<br /><br />";
echo "It is an <strong>$fileType</strong> type of file.<br /><br />";
echo "The file extension is <strong>$fileExt</strong><br /><br />";
echo "The Error Message output for this upload is: $fileErrorMsg";
?>
Archivo ak_php_img_lib_1.0.php:
Código PHP:
Ver original<?php
// Adam Khoury PHP Image Function Library 1.0
// ----------------------- RESIZE FUNCTION -----------------------
// Function for resizing any jpg, gif, or png image files
function ak_img_resize($target, $newcopy, $w, $h, $ext) {
$scale_ratio = $w_orig / $h_orig;
if (($w / $h) > $scale_ratio) {
$w = $h * $scale_ratio;
} else {
$h = $w / $scale_ratio;
}
$img = "";
if ($ext == "gif"){
} else if($ext =="png"){
} else {
}
// imagecopyresampled(dst_img, src_img, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h)
if ($ext == "gif"){
} else if($ext =="png"){
} else {
}
}
// -------------- THUMBNAIL (CROP) FUNCTION ---------------
// Function for creating a true thumbnail cropping from any jpg, gif, or png image files
function ak_img_thumb($target, $newcopy, $w, $h, $ext) {
$src_x = ($w_orig / 2) - ($w / 2);
$src_y = ($h_orig / 2) - ($h / 2);
$img = "";
if ($ext == "gif"){
} else if($ext =="png"){
} else {
}
if ($ext == "gif"){
} else if($ext =="png"){
} else {
}
}
// ----------------------- IMAGE CONVERT FUNCTION -----------------------
// Function for converting GIFs and PNGs to JPG upon upload
function ak_img_convert_to_jpg($target, $newcopy, $ext) {
$img = "";
if ($ext == "gif"){
} else if($ext =="png"){
}
}
// ----------------------- IMAGE WATERMARK FUNCTION -----------------------
// Function for applying a PNG watermark file to a file after you convert the upload to JPG
function ak_img_watermark($target, $wtrmrk_file, $newcopy) {
$dst_x = ($img_w / 2) - ($wtrmrk_w / 2); // For centering the watermark on any image
$dst_y = ($img_h / 2) - ($wtrmrk_h / 2); // For centering the watermark on any image
imagecopy($img, $watermark, $dst_x, $dst_y, 0, 0, $wtrmrk_w, $wtrmrk_h); }
?>
Se supone que es exactamente lo que quiero, insertar un dibujo que se me visualiza junto con una marca de agua (no hay strings, pero supongo que no costaría nada ponerlos). El problema es que no consigo que se me suba bien el dibujo sin un maldito mensaje de error, y eso que hay un video explicativo y todo aparte que he visto, pero yo veo que está todo igual. No quiero hacerme pesado, si tengo que ofrecer dinero lo ofrezco, 20 o 30 euros, pero es que llega un momento que ya no sé qué sustituir por qué, si sustituyo el uploads por mi directorio de destino da los mismos errores. Necesitaré alguien que me explique las cosas como los niños pequeños (y pensar que he sido capaz de entender cómo se hace un blog multinivel con bases de datos relacionadas y todo, pero es que con la movida esta del GD no puedo).
http://www.youtube.com/watch?v=PFSkPzJNAho (Este es el video, por si veis algo raro que no está en los script)