simun Posted July 10, 2009 Share Posted July 10, 2009 i have a script for upload images that work perfectly, now i have made a form to add a text for each image, but smething is wrong here and i cant fine a problem, anyone have idea how to do that? here is my photos.php <?php $object = new S_Object($_REQUEST['id']); $object->gallery->getPhotos(); $filename = "../files/naslovi/" . $_GET['id']; if (is_dir($filename)) { } else { mkdir("../files/naslovi/" . $_GET['id'], 0777); } ?> <h1>Slike za "<?=$object->sifra?> <?=$object->naziv_hr?>"</h1> <form method="post" enctype="multipart/form-data" class="edit"> <h2 class="fieldset-title">Upload nove slike</h2> <fieldset> <input type="file" name="photo" /> <input type="hidden" name="page" value="<?php echo $_GET['page']; ?>" /> <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" /> <input type="hidden" name="action" value="add_photo" /> <input type="submit" name="submit" value="Dodaj" /> </fieldset> </form> <?php if (! empty($_GET['message'])) { ?> <div class="message"> <?php echo $_REQUEST['message']; ?> </div> <?php } if (is_array($object->gallery->photos)) { ?> <table class="list"> <thead> <tr> <th><a>Pregled</a></th> <th><a>Naziv</a></th> <th><a>Veličina</a></th> <th><a>Dimenzije</a></th> <th><a>Glavna</a></th> <th> </th> </tr> </thead> <?php foreach($object->gallery->photos as $k => $photo) { $info = getimagesize($object->gallery->folder . $photo['filename']); $size = filesize($object->gallery->folder . $photo['filename']); ?> <? $ourFileName = "../files/naslovi/" . $_GET['id'] . "/" . $photo['filename'] . ".txt"; if (file_exists($ourFileName)) { } else { $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fclose($ourFileHandle); } ?> <tr> <td><a class="thickbox" rel="photos1" href="/files/objects/<?=$object->id?>/<?=$photo['filename']?>"><img style="border: 0" src="/images/cache/objects/<?=$object->id?>/<?=$photo['filename']?>/w-200.jpg" /></a></td> <td> <form action="" method="post"> <input name="quantity" type="text" /> <input type="submit" /> </form> <?php $myFile = "../files/naslovi/" . $_GET['id'] . "/" . $photo['filename'] . ".txt"; $fh = fopen($myFile, 'r') or die("can't open file"); $stringData = $_POST['quantity']; fwrite($fh, $stringData); fclose($fh); ?> </td> <td><?=round($size/1024)?> KB</td> <td><?=$info[0]?> x <?=$info[1]?></td> <td><input type="radio" class="main-photo" name="main" id="main-<?=$k?>"<?php if ($photo['fields']['main']) echo ' checked="checked"'; ?> /></td> <td><a onclick="return confirm('Sigurno brisati?')" class="delete" href="?page=<?=$_GET['page']?>&action=delete_photo&id=<?=$object->id?>&filename=<?=$photo['filename']?>">brisanje</a></td> </tr> <?php } ?> </table> <?php } ?> <script type="text/javascript"> /*<![CDATA[*/ $(document).ready(function(){ $('input.main-photo').click(function(){ id = this.id.replace('main-', ''); $.ajax({ url: 'ajax.php', method: 'post', data: '&action=set_main_photo&id=<?=$object->id?>&photo_key=' + id, }); }); }); /*]]>*/ </script> Quote Link to comment https://forums.phpfreaks.com/topic/165461-write-to-txt-file-for-image-title/ Share on other sites More sharing options...
ignace Posted July 10, 2009 Share Posted July 10, 2009 $filename = "../files/naslovi/" . $_GET['id']; .. mkdir("../files/naslovi/" . $_GET['id'], 0777); Assume i would pass this to your script: ?id=../../badassdirectory $filename = "../files/naslovi/../../badassdirectory"; // i.e. ../badassdirectory mkdir("../files/naslovi/../../badassdirectory", 0777); You now have an additional directory (possibly) in your root. P.S. Use proper indentiation it makes your code readable Quote Link to comment https://forums.phpfreaks.com/topic/165461-write-to-txt-file-for-image-title/#findComment-872675 Share on other sites More sharing options...
simun Posted July 10, 2009 Author Share Posted July 10, 2009 i have to save my .txt files in directory named by id of gallery, then in that folder i store .txt files with name of image, and inside it i would like to write a title for image that would be shown on my site, i have made that folder and text files i generated automatic and in all .txt files write $stringData variable, <?php $object = new S_Object($_REQUEST['id']); $object->gallery->getPhotos(); $filename = "../files/naslovi/" . $_GET['id']; if (is_dir($filename)) { } else { mkdir("../files/naslovi/" . $_GET['id'], 0777); } ?> <h1>Slike za "<?=$object->sifra?> <?=$object->naziv_hr?>"</h1> <form method="post" enctype="multipart/form-data" class="edit"> <h2 class="fieldset-title">Upload nove slike</h2> <fieldset> <input type="file" name="photo" /> <input type="hidden" name="page" value="<?php echo $_GET['page']; ?>" /> <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" /> <input type="hidden" name="action" value="add_photo" /> <input type="hidden" name="action" value="add_photo" /> <input type="submit" name="submit" value="Dodaj" /> </fieldset> </form> <?php if (! empty($_GET['message'])) { ?> <div class="message"> <?php echo $_REQUEST['message']; ?> </div> <?php } if (is_array($object->gallery->photos)) { ?> <table class="list"> <thead> <tr> <th><a>Pregled</a></th> <th><a>Naziv</a></th> <th><a>Veličina</a></th> <th><a>Dimenzije</a></th> <th><a>Glavna</a></th> <th> </th> </tr> </thead> <?php foreach($object->gallery->photos as $k => $photo) { $info = getimagesize($object->gallery->folder . $photo['filename']); $size = filesize($object->gallery->folder . $photo['filename']); ?> <? $ourFileName = "../files/naslovi/" . $_GET['id'] . "/" . $photo['filename'] . ".txt"; if (file_exists($ourFileName)) { } else { $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fclose($ourFileHandle); } $myFile = "../files/naslovi/" . $_GET['id'] . "/" . $photo['filename'] . ".txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "????????????????????????"; fwrite($fh, $stringData); fclose($fh); ?> <tr> <td><a class="thickbox" rel="photos1" href="/files/objects/<?=$object->id?>/<?=$photo['filename']?>"><img style="border: 0" src="/images/cache/objects/<?=$object->id?>/<?=$photo['filename']?>/w-200.jpg" /></a></td> <td> <form action="" method="post"> <input name="quantity" type="text" /> <input type="submit" /> </form> <?php ?> </td> <td><?=round($size/1024)?> KB</td> <td><?=$info[0]?> x <?=$info[1]?></td> <td><input type="radio" class="main-photo" name="main" id="main-<?=$k?>"<?php if ($photo['fields']['main']) echo ' checked="checked"'; ?> /></td> <td><a onclick="return confirm('Sigurno brisati?')" class="delete" href="?page=<?=$_GET['page']?>&action=delete_photo&id=<?=$object->id?>&filename=<?=$photo['filename']?>">brisanje</a></td> </tr> <?php } ?> </table> <?php } ?> <script type="text/javascript"> /*<![CDATA[*/ $(document).ready(function(){ $('input.main-photo').click(function(){ id = this.id.replace('main-', ''); $.ajax({ url: 'ajax.php', method: 'post', data: '&action=set_main_photo&id=<?=$object->id?>&photo_key=' + id, }); }); }); /*]]>*/ </script> i have to make that $stringData is added by a form for each image, and i can make it :-X any idea ??? Quote Link to comment https://forums.phpfreaks.com/topic/165461-write-to-txt-file-for-image-title/#findComment-872679 Share on other sites More sharing options...
simun Posted July 10, 2009 Author Share Posted July 10, 2009 i have make to work that what i asked above, now onley my form put text in all .txt documents and not in onley imagename.txt document here is the code <?php $object = new S_Object($_REQUEST['id']); $object->gallery->getPhotos(); $filename = "../files/naslovi/" . $_GET['id']; if (is_dir($filename)) { } else { mkdir("../files/naslovi/" . $_GET['id'], 0777); } ?> <h1>Slike za "<?=$object->sifra?> <?=$object->naziv_hr?>"</h1> <form method="post" enctype="multipart/form-data" class="edit"> <h2 class="fieldset-title">Upload nove slike</h2> <fieldset> <input type="file" name="photo" /> <input type="hidden" name="page" value="<?php echo $_GET['page']; ?>" /> <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" /> <input type="hidden" name="action" value="add_photo" /> <input type="hidden" name="action" value="add_photo" /> <input type="submit" name="submit" value="Dodaj" /> </fieldset> </form> <?php if (! empty($_GET['message'])) { ?> <div class="message"> <?php echo $_REQUEST['message']; ?> </div> <?php } if (is_array($object->gallery->photos)) { ?> <table class="list"> <thead> <tr> <th><a>Pregled</a></th> <th><a>Naziv</a></th> <th><a>Veličina</a></th> <th><a>Dimenzije</a></th> <th><a>Glavna</a></th> <th> </th> </tr> </thead> <?php foreach($object->gallery->photos as $k => $photo) { $info = getimagesize($object->gallery->folder . $photo['filename']); $size = filesize($object->gallery->folder . $photo['filename']); ?> <? $ourFileName = "../files/naslovi/" . $_GET['id'] . "/" . $photo['filename'] . ".txt"; if (file_exists($ourFileName)) { } else { $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fclose($ourFileHandle); } $myFile = "../files/naslovi/" . $_GET['id'] . "/" . $photo['filename'] . ".txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = $_POST['quantity']; fwrite($fh, $stringData); fclose($fh); ?> <tr> <td><a class="thickbox" rel="photos1" href="/files/objects/<?=$object->id?>/<?=$photo['filename']?>"><img style="border: 0" src="/images/cache/objects/<?=$object->id?>/<?=$photo['filename']?>/w-200.jpg" /></a></td> <td> <? echo $photo['filename'];?> <form action="" method="post"> <input name="quantity" type="text" value="<? echo $stringData;?>"/> <input type="submit" value="Dodaj" /> </form> </td> <td><?=round($size/1024)?> KB</td> <td><?=$info[0]?> x <?=$info[1]?></td> <td><input type="radio" class="main-photo" name="main" id="main-<?=$k?>"<?php if ($photo['fields']['main']) echo ' checked="checked"'; ?> /></td> <td><a onclick="return confirm('Sigurno brisati?')" class="delete" href="?page=<?=$_GET['page']?>&action=delete_photo&id=<?=$object->id?>&filename=<?=$photo['filename']?>">brisanje</a></td> </tr> <?php } ?> </table> <?php } ?> <script type="text/javascript"> /*<![CDATA[*/ $(document).ready(function(){ $('input.main-photo').click(function(){ id = this.id.replace('main-', ''); $.ajax({ url: 'ajax.php', method: 'post', data: '&action=set_main_photo&id=<?=$object->id?>&photo_key=' + id, }); }); }); /*]]>*/ </script> i think my foreach have a bug somewere or ??? please some help Quote Link to comment https://forums.phpfreaks.com/topic/165461-write-to-txt-file-for-image-title/#findComment-872699 Share on other sites More sharing options...
ignace Posted July 10, 2009 Share Posted July 10, 2009 Add this: <input name="quantity" type="text" value="<? echo $stringData;?>"/> To this: <form method="post" enctype="multipart/form-data" class="edit"> <h2 class="fieldset-title">Upload nove slike</h2> <fieldset> <input type="file" name="photo" /> <input type="hidden" name="page" value="<?php echo $_GET['page']; ?>" /> <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" /> <input type="hidden" name="action" value="add_photo" /> <input type="hidden" name="action" value="add_photo" /> <input type="submit" name="submit" value="Dodaj" /> </fieldset> </form> Change: if (file_exists($ourFileName)) { } else { $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fclose($ourFileHandle); } To: if (!empty($_POST['quantity'])) { $quantity = $_POST['quantity']; $ourFileHandle = fopen($ourFileName, 'w'); if ($ourFileHandle) { fwrite($fh, $quantity); fclose($ourFileHandle); } } Quote Link to comment https://forums.phpfreaks.com/topic/165461-write-to-txt-file-for-image-title/#findComment-872701 Share on other sites More sharing options...
simun Posted July 10, 2009 Author Share Posted July 10, 2009 i think u dont undersand me, this form that u told me to do i for upload images, below is form for upload titles, i need first to upload image, and then upload a title, when i change a image name it change names off all images, that is my problem. Quote Link to comment https://forums.phpfreaks.com/topic/165461-write-to-txt-file-for-image-title/#findComment-872705 Share on other sites More sharing options...
ignace Posted July 10, 2009 Share Posted July 10, 2009 You need a new page, then when a user wants to edit a certain image: <input type="hidden" name="filename" value="<?php print $photo['filename']; ?>"> <input type="hidden" name="action" value="update_image"> <input type="text" name="caption" value="<?php print $photo['caption']; ?>"> And add this php code: <?php if (!empty($_POST['action']) && $_POST['action'] === 'update_image') { $id = $_GET['id']; $filename = $_POST['filename']; $caption = $_POST['caption']; $filelocation = "../files/naslovi/$id/$filename.txt"; $fh = fopen($filelocation, 'w'); if ($fh) { fwrite($caption); fclose($fh); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/165461-write-to-txt-file-for-image-title/#findComment-872720 Share on other sites More sharing options...
simun Posted July 10, 2009 Author Share Posted July 10, 2009 interesting idea, but it wont work to me here is my page with form: <?php $object = new S_Object($_REQUEST['id']); $object->gallery->getPhotos(); $filename = "../files/naslovi/" . $_GET['id']; if (is_dir($filename)) { } else { mkdir("../files/naslovi/" . $_GET['id'], 0777); } ?> <h1>Slike za "<?=$object->sifra?> <?=$object->naziv_hr?>"</h1> <form method="post" enctype="multipart/form-data" class="edit"> <h2 class="fieldset-title">Upload nove slike</h2> <fieldset> <input type="file" name="photo" /> <input type="hidden" name="page" value="<?php echo $_GET['page']; ?>" /> <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" /> <input type="hidden" name="action" value="add_photo" /> <input type="hidden" name="action" value="add_photo" /> <input type="submit" name="submit" value="Dodaj" /> </fieldset> </form> <?php if (! empty($_GET['message'])) { ?> <div class="message"> <?php echo $_REQUEST['message']; ?> </div> <?php } if (is_array($object->gallery->photos)) { ?> <table class="list"> <thead> <tr> <th><a>Pregled</a></th> <th><a>Naziv</a></th> <th><a>Veličina</a></th> <th><a>Dimenzije</a></th> <th><a>Glavna</a></th> <th> </th> </tr> </thead> <?php foreach($object->gallery->photos as $k => $photo) { $info = getimagesize($object->gallery->folder . $photo['filename']); $size = filesize($object->gallery->folder . $photo['filename']); ?> <? $ourFileName = "../files/naslovi/" . $_GET['id'] . "/" . $photo['filename'] . ".txt"; if (file_exists($ourFileName)) { } else { $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fclose($ourFileHandle); } $myFile = "../files/naslovi/" . $_GET['id'] . "/" . $photo['filename'] . ".txt"; $fh = fopen($myFile, 'w') or die("can't open file"); ?> <?php if (!empty($_POST['action']) && $_POST['action'] === 'update_image') { $id = $_GET['id']; $filename = $_POST['filename']; $caption = $_POST['caption']; $filelocation = "../files/naslovi/$id/$filename.txt"; $fh = fopen($filelocation, 'w'); if ($fh) { fwrite($caption); fclose($fh); } } ?> <tr> <td><a class="thickbox" rel="photos1" href="/files/objects/<?=$object->id?>/<?=$photo['filename']?>"><img style="border: 0" src="/images/cache/objects/<?=$object->id?>/<?=$photo['filename']?>/w-200.jpg" /></a></td> <td> <? echo $photo['filename']; $putanja = substr("../files/naslovi/" . $_GET['id'] . "/" . $photo['filename'] . ".txt", -20, -4); if ($photo['filename'] == $putanja){echo "ok";} else {echo "ne";} ?> <form action="pages/process.php?id=<?=$object->id?>" method="post"> <input type="hidden" name="filename" value="<?php print $photo['filename']; ?>"> <input type="hidden" name="action" value="update_image"> <input type="text" name="caption" value="<?php print $photo['caption']; ?>"> <input type="submit" value="Dodaj" /> </form> </td> <td><?=round($size/1024)?> KB</td> <td><?=$info[0]?> x <?=$info[1]?></td> <td><input type="radio" class="main-photo" name="main" id="main-<?=$k?>"<?php if ($photo['fields']['main']) echo ' checked="checked"'; ?> /></td> <td><a onclick="return confirm('Sigurno brisati?')" class="delete" href="?page=<?=$_GET['page']?>&action=delete_photo&id=<?=$object->id?>&filename=<?=$photo['filename']?>">brisanje</a></td> </tr> <?php } ?> </table> <?php } ?> <script type="text/javascript"> /*<![CDATA[*/ $(document).ready(function(){ $('input.main-photo').click(function(){ id = this.id.replace('main-', ''); $.ajax({ url: 'ajax.php', method: 'post', data: '&action=set_main_photo&id=<?=$object->id?>&photo_key=' + id, }); }); }); /*]]>*/ </script> and here new page with code: <?php if (!empty($_POST['action']) && $_POST['action'] === 'update_image') { $id = $_GET['id']; $filename = $_POST['filename']; $caption = $_POST['caption']; $filelocation = "../../files/naslovi/$id/$filename.txt"; $fh = fopen($filelocation, 'w'); if ($fh) { fwrite($caption); fclose($fh); } } ?> i cant undestand it Quote Link to comment https://forums.phpfreaks.com/topic/165461-write-to-txt-file-for-image-title/#findComment-872759 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.