Jump to content
  • 0

деление строки


Simon
 Share

Question

Товарищи, помогите:

в результате перебора массива получаю вот такую строку

$line = 'image0655b.pngimaged8ef4.jpgimaged8ef4.png';

как можно разделить эту строку на

image0655b.png, imaged8ef4.jpg, imaged8ef4.png

Edited by Simon
Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

$j=0;
for($i = 0; $i <= 2; $i++)
{
if (!empty($_FILES['files']['name'][$i]))
{
$arrr[$j] = $_FILES['files']['name'][$i];
$j++;
}
}
foreach ($arrr as $key => $val)
{
$path_info = pathinfo($arrr[$key]);
$path_ext = $path_info['extension'];
$n .= 'image'.substr(md5($val),0,5).'.'.$path_ext;
}

$qu = mysql_query("INSERT INTO images SET img = '$n'");

Edited by Simon
Link to comment
Share on other sites

  • 0

сорри, проблему решил:

foreach ($arrr as $key => $val)
{
$ar1 = array();
for ($y=0; $y<=$key;$y++)
{
$path_info = pathinfo($arrr[$y]);
$path_ext = $path_info['extension'];
$ar1[$y] = 'image'.substr(md5(microtime().$arrr[$y]),0,5).'.'.$path_ext;
}
}
$imp = implode(', ',$ar1);
echo $imp;

не ну блин пока не напишу на форуме не найду решение...так всегда(( а ведь целый день убил на такой пустяк((

Edited by Simon
Link to comment
Share on other sites

  • 0

$sub = substr($arrr[$y],0,5);
$ar1[$y] = 'image'.substr(md5(microtime().$sub),0,5).'.'.$path_ext;
$full = $dir.$ar1[$y];
$m = move_uploaded_file($_FILES['files']['tmp_name'][$key], $full);

move_uploaded_file загружает только 1 изображение и с другим названием не то что генерирую и афиширую ((

Edited by Simon
Link to comment
Share on other sites

  • 0


$sub = substr($arrr[$y],0,5);
$ar1[$y] = 'image'.substr(md5(microtime().$sub),0,5).'.'.$path_ext;
$full[$y] = $dir.$ar1[$y];
move_uploaded_file($_FILES['files']['tmp_name'][$y], $full[$y]);

$ar1 выдает

image492a3.png, imagea7dba.png

print_r($full);

Array ( [0] => ../uploads/image492a3.png [1] => ../uploads/imagea7dba.png )

print_r($_FILES['files']['tmp_name']);

Array ( [0] => Z:\tmp\php4D0.tmp [1] => [2] => Z:\tmp\php4D2.tmp )

могут быть проблемы и за тмп файлов?

Edited by Simon
Link to comment
Share on other sites

  • 0

for ($y=0, $z=0; $y<=$key;$y++, $z++)
{
$ar2[$y][$z] = pathinfo($arrr[$y]);
$ar2[$y][$z] = $ar2[$y][$z]['extension'];

$ar1[$y] = 'image'.substr(md5(time().$arrr[$y]),0,5).'.'.$ar2[$y][$z];
$full[$y] = $dir.$ar1[$y];

$m[$y] = move_uploaded_file($_FILES['files']['tmp_name'][$y], $full[$y]);

}

загружается только первый файл...а 2ой не хочет,почему?(( при выводе $full оба файла на месте :)

ап, наконец-то сделал....пришлось и tmp файлы пересортировать, т.к. они получали индекс другой ;)

Edited by Simon
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  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.

 Share

×
×
  • 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. See more about our Guidelines and Privacy Policy