Ciao a tutti. Ho un file php che mi carica delle immagini e dei testi.
Io vorrei per ogni immagine caricata, tramite php scrivere sul file images.xml una riga che aggiunge l'immagine caricata.
Sono disperata anche perchè davvero di php ci capisco poco.
Grazie in anticipo
Il mio xml è così composto:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
- <images>
- <pic>
<image>\public\inserisci\image_files\aria01.jpg</image>
</pic>
- <pic>
<image>\public\inserisci\image_files\aria02.jpg</image>
</pic>
</images>
Mentre la pagina che carica le immagini è la seguente:
<?php ini_set("memory_limit", "200000000"); // for large images so that we do not get "Allowed memory exhausted"?>
<?php
// upload the file
if ((isset($_POST["submitted_form"])) && ($_POST["submitted_form"] == "image_upload_form")) {
// file needs to be jpg,gif,bmp,x-png and 4 MB max
if (($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg" || $_FILES["image_upload_box"]["type"] == "image/gif" || $_FILES["image_upload_box"]["type"] == "image/x-png") && ($_FILES["image_upload_box"]["size"] < 4000000))
{
// some settings
$max_upload_width = 2592;
$max_upload_height = 1944;
// if user chosed properly then scale down the image according to user preferances
if(isset($_REQUEST['max_width_box']) and $_REQUEST['max_width_box']!='' and $_REQUEST['max_width_box']<=$max_upload_width){
$max_upload_width = $_REQUEST['max_width_box'];
}
if(isset($_REQUEST['max_height_box']) and $_REQUEST['max_height_box']!='' and $_REQUEST['max_height_box']<=$max_upload_height){
$max_upload_height = $_REQUEST['max_height_box'];
}
// if uploaded image was JPG/JPEG
if($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg"){
$image_source = imagecreatefromjpeg($_FILES["image_upload_box"]["tmp_name"]);
}
// if uploaded image was GIF
if($_FILES["image_upload_box"]["type"] == "image/gif"){
$image_source = imagecreatefromgif($_FILES["image_upload_box"]["tmp_name"]);
}
// BMP doesn't seem to be supported so remove it form above image type test (reject bmps)
// if uploaded image was BMP
if($_FILES["image_upload_box"]["type"] == "image/bmp"){
$image_source = imagecreatefromwbmp($_FILES["image_upload_box"]["tmp_name"]);
}
// if uploaded image was PNG
if($_FILES["image_upload_box"]["type"] == "image/x-png"){
$image_source = imagecreatefrompng($_FILES["image_upload_box"]["tmp_name"]);
}
$remote_file = "image_files/".$_FILES["image_upload_box"]["name"];
imagejpeg($image_source,$remote_file,100);
chmod($remote_file,0644);
// get width and height of original image
list($image_width, $image_height) = getimagesize($remote_file);
if($image_width>$max_upload_width || $image_height >$max_upload_height){
$proportions = $image_width/$image_height;
if($image_width>$image_height){
$new_width = $max_upload_width;
$new_height = round($max_upload_width/$proportions);
}
else{
$new_height = $max_upload_height;
$new_width = round($max_upload_height*$proportions);
}
$new_image = imagecreatetruecolor($new_width , $new_height);
$image_source = imagecreatefromjpeg($remote_file);
imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
imagejpeg($new_image,$remote_file,100);
imagedestroy($new_image);
}
imagedestroy($image_source);
header("Location: submit.php?upload_message=IMMAGINE INSERITA CORRETTAMENTE&upload_message_type=success&show_ima ge=".$_FILES["image_upload_box"]["name"]);
exit;
}
else{
header("Location: submit.php?upload_message=IMMAGINE NON INSERITA&upload_message_type=error");
exit;
}
}
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Fiorepentafaretra - Pannello di amministrazione</title>
<style type="text/css">
<!--
body,td,th {
}
.upload_message_success {
padding:4px;
background-color:#009900;
border:1px solid #006600;
color:#FFFFFF;
margin-top:10px;
margin-bottom:10px;
}
.upload_message_error {
padding:4px;
background-color:#CE0000;
border:1px solid #990000;
color:#FFFFFF;
margin-top:10px;
margin-bottom:10px;
}
.Stile1 {
font-size: 16px
}
body {
background-color: #A6733E;
}
.Stile4 {
color: #333333;
font-family: Verdana;
font-size: 12px;
font-weight: bold;
}
.Stile5 {color: #FFFFFF; font-weight: bold; font-size: 12px; }
.Stile6 {
font-family: Verdana;
font-weight: bold;
}
.Stile7 {font-size: 12px}
-->
</style>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>
<body>
<table width="500" border="2" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
<tr>
<td><table width="100%" border="0" bgcolor="#E6E6E6">
<tr>
<td> <h1 align="center" class="Stile1" style="margin-bottom: 0px">[img]su_submit.jpg[/img]</h1>
<?php if(isset($_REQUEST['upload_message'])){?>
<div class="upload_message_<?php echo $_REQUEST['upload_message_type'];?>">
<div align="center"><?php echo htmlentities($_REQUEST['upload_message']);?> </div>
</div>
<?php }?>
<table width="100%" border="0" align="center"> <td bgcolor="#742425"><div align="center" class="Stile5">INSERISCI UN'IMMAGINE</div></td>
<tr>
<td><table width="100%" border="0" align="center">
<tr>
</tr>
</table>
<form action="submit.php" method="post" enctype="multipart/form-data" name="image_upload_form" id="image_upload_form" style="margin-bottom:0px;">
<label>L'immagine non può superare 4MB e deve necessariamente essere una jpg.</label>
La dimensione esatta dell'immagine deve essere 520 x 314 px.
Ogni immagine deve avere il nome della sezione di riferimento :
homepage.jpg;
acqua.jpg;
aria.jpg;
fuoco.jpg;
spirito.jpg;
terra.jpg
<table width="500" border="0">
<tr>
<td width="359"><div align="right">
<input name="image_upload_box" type="file" id="image_upload_box" size="30" />
</div></td>
<td width="131"><div align="left">
<input type="submit" name="submit" value="Inserisci" />
</div></td>
</tr>
</table>
<div align="left"></div>
<label></label>
<div align="center">
<input name="submitted_form" type="hidden" id="submitted_form" value="image_upload_form" />
</div>
</form></td>
</tr>
</table>
<div align="center">
<?php if(isset($_REQUEST['show_image']) and $_REQUEST['show_image']!=''){?>
</div>
<div align="center">
<?php }?>
</div></td>
</tr>
</table>
<table width="100%" border="0" align="center" bgcolor="#E6E6E6">
<tr>
<td><form action="crea_homepage.php" method="post" name="form" id="form" onsubmit="if (nome.value=='') {alert('Inserisci il testo per la homepage'); return false;}">
<center>
<table width="500" border="0">
<tr>
<td colspan="2" bgcolor="#742425"><div align="center" class="Stile5">MODIFICA IL TESTO DELLE TUE PAGINE</div></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><div align="center">Sezione homepage</div></td>
</tr>
<tr>
<td width="359"><div align="right">
<textarea name="nome" type="text" class="login_home" id="nome" value="" cols="40" rows="2"></textarea>
</div></td>
<td width="131"><div align="left">
<input type="submit" name="Submit" id="Submit" value="Inserisci Homepage" />
</div></td>
</tr>
</table>
</form>
<form action="crea_aria.php" method="post" name="form" id="form" onsubmit="if (nome1.value=='') {alert('Inserisci il testo per la sezione aria'); return false;}">
<table width="500" border="0">
<tr>
<td colspan="2"><div align="center">Sezione aria</div></td>
</tr>
<tr>
<td width="359"><div align="right">
<textarea name="nome1" type="text" class="login_home" id="nome1" value="" cols="40" rows="2"></textarea>
</div></td>
<td width="131"><div align="left">
<input type="submit" name="Submit1" id="Submit1" value="Inserisci Aria" />
</div></td>
</tr>
</table>
</form>
<form action="crea_acqua.php" method="post" name="form" id="form" onsubmit="if (nome2.value=='') {alert('Inserisci il testo'); return false;}">
<table width="500" border="0">
<tr>
<td colspan="2"><div align="center">Sezione acqua</div></td>
</tr>
<tr>
<td width="359"><div align="right">
<textarea name="nome2" type="text" class="login_home" id="nome2" value="" cols="40" rows="2"></textarea>
</div></td>
<td width="131"><div align="left">
<input type="submit" name="Submit2" id="Submit2" value="Inserisci Acqua" />
</div></td>
</tr>
</table>
</form>
<form action="crea_terra.php" method="post" name="form" id="form" onsubmit="if (nome3.value=='') {alert('Inserisci il testo'); return false;}">
<table width="500" border="0">
<tr>
<td colspan="2"><div align="center">Sezione terra</div></td>
</tr>
<tr>
<td width="359"><div align="right">
<textarea name="nome3" type="text" class="login_home" id="nome4" value="" cols="40" rows="2"></textarea>
</div></td>
<td width="131"><div align="left">
<input type="submit" name="Submit3" id="Submit3" value="Inserisci Terra" />
</div></td>
</tr>
</table>
</form>
<form action="crea_fuoco.php" method="post" name="form" id="form" onsubmit="if (nome4.value=='') {alert('Inserisci il testo'); return false;}">
<table width="500" border="0">
<tr>
<td colspan="2"><div align="center">Sezione fuoco</div></td>
</tr>
<tr>
<td width="359"><div align="right">
<textarea name="nome4" type="text" class="login_home" id="nome4" value="" cols="40" rows="2"></textarea>
</div></td>
<td width="131"><div align="left">
<input type="submit" name="Submit4" id="Submit4" value="Inserisci Fuoco" />
</div></td>
</tr>
</table>
</form>
<form action="crea_spirito.php" method="post" name="form" id="form" onsubmit="if (nome5.value=='') {alert('Inserisci il testo'); return false;}">
<table width="500" border="0">
<tr>
<td colspan="2"><div align="center">Sezione spirito</div></td>
</tr>
<tr>
<td width="359"><div align="right">
<textarea name="nome5" type="text" class="login_home" id="nome5" value="" cols="40" rows="2"></textarea>
</div></td>
<td width="131"><div align="left">
<input type="submit" name="Submit5" id="Submit5" value="Inserisci Spirito" />
</div></td>
</tr>
</table>
</form></td>
</tr>
</table>
</tr>
</table>
</body>
</html>