Consiglio per sito
-
Ciao a tutti!..
espongo il mio problema...
Vorrei realizzare un sito per la pubblicazione di immagini di magliette; mi servirebbe cioè un area admin dove uploadare le immagini con autore e breve descrizione, per poi essere richiamate in una pagina che le mostra. Sinceramente ho seguito molti tutorial, ma sono molto gnubbo e non sono riuscito a raggiungere il mio scopo.:x.non o capito come gestire le immagini inserite in mysql.
Qualche anima buona potrebbe indicarmi la retta via o qualche tutorial anche inglese?
grazie a tutti!
ciao! -
-
vuoi fare tutto tu giusto?
bhè io ti consiglierei di fare un passo alla volta:
inizia a creare la struttura per l'upload delle img sul server...ATTENZIONE sul SERVER e non nel database mysql potrebbe risultarti molto più semplice... inoltre se fai un po' di ricerche sicuramente ti uscirà qualche materiale utile... -
-
fai in questo modo:
nel db segni un id una descrizione un autore ed in più un campo che abbia in se l'indirizzo dell'immagine in modo da inserire quel vaore nel campo img

-
-
ciao..scusa se insisto..ma ho molti problemi..
ho trovato uno script che fa un bell'upload di immagini e anche swf..me le fa visualizzate tutte in una pagina (esempio http://tshop.altervista.org/upload-mmkit/upload.php)vorrei che cliccando su una foto mi aprisse una pagine tutta sua :?... dove ci sarà presente un form da compilare per ricevere info...uffi sto impazzendo il php non riesco a capirlo.. se ti andrà ancora di aiutarmi, questo è il codice, grazie mille a tutti:upload.php
<?php // global variables $my_max_file_size = "307200"; # in bytes $image_max_width = "400"; $image_max_height = "500"; $registered_types = array( "application/x-gzip-compressed" => ".tar.gz, .tgz", "application/x-zip-compressed" => ".zip", "application/x-tar" => ".tar", "text/plain" => ".html, .php, .txt, .inc", "image/bmp" => ".bmp, .ico", "image/gif" => ".gif", "image/pjpeg" => ".jpg, .jpeg", "image/jpeg" => ".jpg, .jpeg", "application/x-shockwave-flash" => ".swf", "application/msword" => ".doc", "application/vnd.ms-excel" => ".xls", "application/octet-stream" => ".exe, .fla" ); # these are only a few examples, you can find many more! $allowed_types = array("image/gif","image/pjpeg","image/jpeg","application/x-shockwave-flash"); //end global variables function dbconnect() { mysql_connect("localhost", "***", "+++"); @mysql_select_db("***") or die ("Unable to select database"); } function delete($id) { mysql_query("delete from mmkit_images WHERE id=$id"); Header("Location: upload.php"); } function mod($id) { global $PHP_SELF, $my_max_file_size, $image_max_width, $image_max_height; echo"<html><head><title>Uploading Files</title> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head> <body bgcolor=\"#EAEAEA\">"; echo "\n<form ENCTYPE=\"multipart/form-data\" action=\"" . $PHP_SELF . "\" method=\"post\">"; echo "\n<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"" . $my_max_file_size . "\">"; echo "\n<P><CENTER><h2><b>Modifica immagine id=$id</b></center></h2>"; echo "\n<br><b>File</b>: <INPUT NAME=\"thefile\" TYPE=\"file\" SIZE=\"35\"><br>"; echo "\n<BR>dimensione massima: " . ($my_max_file_size / 1024) . "KB - ".$image_max_width."x".$image_max_height." pixel"; echo "<input type=\"hidden\" name=\"id\" value=\"$id\"><input type=\"hidden\" name=\"task\" value=\"change\">"; echo "\n<br><input type=\"submit\" Value=\"Invia\">"; echo "\n</form>"; echo"</body></html>"; } # END form function form($error=false) { global $PHP_SELF, $my_max_file_size, $image_max_width, $image_max_height; echo"<html><head><title>Uploading Files</title> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head> <body bgcolor=\"#EAEAEA\">"; if ($error) print $error . "<br><br>"; echo "\n<form ENCTYPE=\"multipart/form-data\" action=\"" . $PHP_SELF . "\" method=\"post\">"; echo "\n<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"" . $my_max_file_size . "\">"; echo "\n<INPUT TYPE=\"hidden\" name=\"task\" value=\"upload\">"; echo "\n<P><CENTER><h2><b>Upload Files</b></center></h2>"; echo "\n<br><b>File</b>: <INPUT NAME=\"thefile\" TYPE=\"file\" SIZE=\"35\"><br>"; echo "\n<BR>dimensione massima: " . ($my_max_file_size / 1024) . "KB - ".$image_max_width."x".$image_max_height." pixel"; echo "\n<br><input type=\"submit\" Value=\"Invia\">"; echo "\n</form>"; list_files(); echo"</body></html>"; } # END form function validate_upload($thefile) { global $my_max_file_size, $image_max_width, $image_max_height, $allowed_types, $thefile_type, $registered_types, $g_height, $g_width, $thefile_name; $start_error = "\n<b>Si sono verificati i seguenti errori:</b>\n<ul>"; if ($thefile == "none") { $error .= "\n<li>Nessun file selezionato</li>"; } else { if (!in_array($thefile_type, $allowed_types)) { $error .= "\n<li>Il file non appartiene a queste tipologie: <br>\n<ul>"; while ($type = current($allowed_types)) { $error .= "\n<li>" . $registered_types[$type] . " (" . $type . ")</li>"; next($allowed_types); } $error .= "\n</ul>"; } if (ereg("image", $thefile_type) && in_array($thefile_type, $allowed_types)) { $size = GetImageSize($thefile); list($foo,$width,$bar,$height) = explode("\"",$size[3]); $g_width=$width; if ($width > $image_max_width) { $error .= "\n<li>La larghezza dell'immagine non deve superare " . $image_max_width . " pixel</li>"; } $g_height=$height; if ($height > $image_max_height) { $error .= "\n<li>L'altezza dell'immagine non deve superare " . $image_max_height . " pixels</li>"; } } if (ereg("flash", $thefile_type) && in_array($thefile_type, $allowed_types)) { $size = GetImageSize($thefile); list($foo,$width,$bar,$height) = explode("\"",$size[3]); $g_width=$width; $g_height=$height; if (($width > $image_max_width) || ($height > $image_max_height)) { if ($width >= $height) { $g_width=$image_max_width; $g_height=intval($height*$image_max_width/$width); } else { $g_height=$image_max_height; $g_width=intval($width*$image_max_height/$height); } } } if ($error) { $error = $start_error . $error . "\n</ul>"; return $error; } else { return false; } } } # END validate_upload function list_files() { $result=mysql_query("select id, filename, filetype, filewidth, fileheight from mmkit_images"); if (mysql_num_rows($result) > 0) { echo"<table width=\"98%\" border=\"1\" cellspacing=\"1\" cellpadding=\"1\" bordercolor=\"#000000\"><tr bgcolor=\"#999999\"><td>Files presenti nel database:</td></tr>"; while(list($id, $filename, $filetype, $width, $height, $autore, $desc)=mysql_fetch_row($result)) { echo"<tr bgcolor=\"#cccccc\"><td><a href=\"upload.php?task=delete&id=$id\">Delete</a> - <a href=\"upload.php?task=mod&id=$id\">Modify</a></td></tr>"; if (ereg("flash", $filetype)) { echo"<tr bgcolor=\"#FFFFFF\"><td><object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" width=\"$width\" height=\"$height\"><param name=movie value=\"getdata.php?id=$id\"><param name=quality value=high><embed src=\"getdata.php?id=$id\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"$width\" height=\"$height\"></embed></object></td> </tr>"; } else { echo"<tr bgcolor=\"#FFFFFF\"><td><img src=\"getdata.php?id=$id\" width=\"$width\" height=\"$height\"></td> </tr>"; } } echo"</table>"; } else echo"<br>Il database è vuoto."; }//end list_files function change($thefile, $id) { global $thefile_name, $thefile_type, $thefile_size, $g_width, $g_height; $error = validate_upload($thefile); if ($error) { form($error); } else { $fp=@fopen($thefile, "r"); if ($fp) { $data = addslashes(fread($fp, filesize($thefile))); $result=MYSQL_QUERY("UPDATE mmkit_images SET bin_data='$data', filename='$thefile_name', filesize='$thefile_size', filetype='$thefile_type', filewidth='$g_width', fileheight='$g_height' WHERE id=$id"); fclose($fp); if (!$result) { echo mysql_errno(). ": ".mysql_error(). "<br>"; exit();} else Header("Location: upload.php"); } else { echo"Il file selezionato non è valido, probabilmente è vuoto.<br><a href=\"javascript:history.back()\">Clicca qui</a> per tornare indietro."; fclose($fp); } } } # END upload function upload($thefile) { global $thefile_name, $thefile_type, $thefile_size, $g_width, $g_height; $error = validate_upload($thefile); if ($error) { form($error); } else { $fp=@fopen($thefile, "r"); if ($fp) { $data = addslashes(fread($fp, filesize($thefile))); $result=MYSQL_QUERY("INSERT INTO mmkit_images VALUES ('NULL', '$data','$thefile_name','$thefile_size','$thefile_type', '$g_width', '$g_height')"); fclose($fp); if (!$result) { echo mysql_errno(). ": ".mysql_error(). "<br>"; exit();} else Header("Location: upload.php"); } else { echo"Il file selezionato non è valido, probabilmente è vuoto.<br><a href=\"javascript:history.back()\">Clicca qui</a> per tornare indietro."; fclose($fp); } } } # END upload dbconnect(); switch($task) { case 'upload': upload($thefile); break; case 'delete': delete($id); break; case 'mod': mod($id); break; case 'change': change($thefile, $id); break; default: form($error); } ?> GETDATA.PHP <?php function dbconnect() { mysql_connect("localhost", "xxx", "xxx"); @mysql_select_db("xxx") or die ("Unable to select database"); } dbconnect(); if($id) { $query = "select bin_data, filetype FROM mmkit_images WHERE id='$id'"; $result = @MYSQL_QUERY($query); $data = @MYSQL_RESULT($result,0,"bin_data"); $type = @MYSQL_RESULT($result,0,"filetype"); Header("Content-type: $type"); echo $data; }; ?> INDEX.PHP <form ENCTYPE="multipart/form-data" action="upload.php" method="post"> <p> <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="307200"> <INPUT TYPE="hidden" name="task" value="upload"> <br> <b>File</b>: <INPUT NAME="thefile" TYPE="file" SIZE="35"> <br> <input type="submit" Value="Invia"> </p> </form>
Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.
Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.
Con il tuo contributo, questo post potrebbe essere ancora migliore 💗
Registrati Accedi
