Jump to content

Recommended Posts

Hi all,

 

Trying to finish a project and have these two niggling problems:

 

I'm using a script which uploads a picture, takes a note of where the picture has been put then outputs

the path to that picture as a string. The string is appended to append to a .txt file which holds an array

of similar paths.

 

The array in the txt file is very simple:

allpics=members/1/images/13.jpg,members/1/images/14.jpg,members/1/images/15.jpg,

 

My questions are, once the script has opened the file

1) how can I append (edit) the array at a certain point i.e. not at the end but after the eighth character (allpics=)?

and

2) how can I then count the commas in the whole array and write that number at the end as a variable "totalimges=123" ?

 

 

Best wishes

Monty

The array in the txt file is very simple:

allpics=members/1/images/13.jpg,members/1/images/14.jpg,members/1/images/15.jpg,

This is not an array it is a string.

 

You should get rid of the allpics=members from this file. I do not understand why it is used in the first path?

Create an array from the comma separator. You can then view the array, convert it back to a string.

I have placed the file in a variable. Use file_get_contents() to read the file.

<?php
$textfile = "allpics=members/1/images/13.jpg,members/1/images/14.jpg,members/1/images/15.jpg";
$textfile = str_replace("allpics=","",$textfile);
$filepaths = explode(",",$textfile);
print "There are ".count($filepaths)." files";

print "<pre>";
print_r($filepaths);
print "</pre>";
?>

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.