Jump to content

When you upload something modify text in the xml file


assasinkilla

Recommended Posts

Hello, i got a flashgallery, and for me to add pictures i must upload the pictures and modify the xml

So any idea how to do this? The upload thing (for specials users only) and to modify the xml when it's uploaded, a place where to put text (that will be the name) that's part of the upload thing, and to make only upload picture format..

 

 

Ty

Link to comment
Share on other sites

Uploading pictures is not that difficult. Im sure u can find a lot of tutorials out there. For the xml thing, if u want to just append data to the file's end, u can use fopen('file.xml', 'a') and fwrite('file.xml', $data). If u are going to modify nodes and stuff, then i dont know.

Link to comment
Share on other sites

Uploading pictures is not that difficult. Im sure u can find a lot of tutorials out there. For the xml thing, if u want to just append data to the file's end, u can use fopen('file.xml', 'a') and fwrite('file.xml', $data). If u are going to modify nodes and stuff, then i dont know.

maybe this post is right for more info look here

http://www.php.net/manual/en/function.fwrite.php

Link to comment
Share on other sites

Ok i wrote u this file upload script

 

<form enctype="multipart/form-data" action="" method="post">
 <input type="file" name="pic" />
 <input type="submit" value="Submit" name="Submit" />
</form>

<?php
if(strlen($_FILES['pic']['name']) > 1){
$file = basename($_FILES['pic']['name']);
$ext = strtolower(substr(strrchr($file, '.'), 1));
$allowedExt = array('jpg', 'png', 'bmp', 'gif', 'tga', 'tif');
$uploadPath = "$file";
$size = $_FILES['pic']['size'] / 1024; // size in kb
$maxSize = 1000; //size in kb
if(in_array($ext, $allowedExt) and $size < $maxSize){
if(move_uploaded_file($_FILES['pic']['tmp_name'], $uploadPath)){
	echo "The image $file was uploaded successfully";
} else{
	echo "An error ocurred during upload. Try again later";
}
} else{
echo "File format is unsupported or filesize is too big";
}
}
?>

 

For the xml part u can use:

 

$file = 'yourFile.xml';
$data = 'some xml data';
$handle = fopen($file, 'a');
fwrite($handle, $data);
fclose($handle);

Link to comment
Share on other sites

If you have to modify XML like in the middle of the file and you don't feel like getting crazy with regular expressions, you could use simplexml or something similar to parse it, add to it, then reconstruct the output file.

 

Also, you probably don't want to do this, but I would suggest using a database if your image records are going to get large.  That way, PHP could generate the XML file based off of a mysql database or something similar, making updating things much easier.  (Depending on how often you update though, that way could be worse performance wise unless caching of some form was used.)

 

Edit: Ahhhh..... Beat to it twice!

Link to comment
Share on other sites

Well im kind of confused :D

 

Well i will explain a litle how gallery works, i will attach the config.xml you will notice almost at the end are divided by sections, well i want people that choose the section, upload and when upload ads in the .xml the info

example

If to add a picture i need to copy this

<img value="name.extension mp3="page-14.mp3" name="Page 13"></img>

 

well to add when it's uploaded, looks kind of hard...

Note: Auto writes the name in the image value

attach: airservers.pirohost.com/ffa/config.xml

thank you for all replies

Best Regards

Mudi

Link to comment
Share on other sites

There we go mudi:

<form enctype="multipart/form-data" action="" method="post">
Song Artist: <input type="text" name="artist" /><br>
Song Name: <input type="text" name="name" /><br>
MP3 File: <input type="file" name="file" /><br>
<input type="submit" value="Submit" name="Submit" />
</form>

<?php
if(strlen($_FILES['file']['name']) > 1)
{
$file = basename($_FILES['file']['name']);
$name = $_POST['name'];
$artist = $_POST['artist'];
$ext = strtolower(substr(strrchr($file, '.'), 1));
$allowedExt = array('mp3');
$uploadPath = "musics";
if(!is_dir($uploadPath))
{
	mkdir($uploadPath,"0777");
}
$uploadPath = $uploadPath."/".$file;
$size = $_FILES['file']['size'] / 1024; // size in kb
$maxSize = 10024; //size in kb
if(in_array($ext, $allowedExt) and $size < $maxSize)
{
	if (file_exists($uploadPath))
	{
    			echo "The file already exists!";
	}
	else
	{
		if(move_uploaded_file($_FILES['file']['tmp_name'], $uploadPath))
		{
			echo "The mp3, $file was uploaded successfully and added to the playlist!";
			$file = 'config.xml';
			$handle = fopen($file, 'r');
			$size=filesize($file);
			$size=$size-21;
			$contents = fread($handle, $size);
			$contents = $contents."#".$uploadPath.",".$artist." - ".$name."</play_list></config>";
			fclose($handle);
			$file = 'config.xml';
			$handle = fopen($file, 'w');
			fwrite($handle, $contents);
			fclose($handle);
		}
		else
		{
			echo "An error ocurred during upload. Try again later";
		}
	}
}
else
{
	echo "File format is unsupported or filesize is too big";
}
}
?>

 

I have just started learning PHP so correct the mistakes but it works fine, no problems at all!

 

Name!!! Holy crap, thats gonna take one hell of a script...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.