$record_directory = ‘./test_folder/’;
The file path for every link is appointed automatically.
I wrote the 19th message before I did not see your message.
I am not quite sure if everything is working now or not - sorry.
If not, could you rephrase the issue your are experiencing for me.
Thanks!
Creating the folder, no problem
file will not load
“failed to open stream: Invalid argument in”
$record_directory = ‘./test_folder/’;
The file path for every link is appointed automatically.
Best Regads, Thank you
Just to make sure, this third section of code works correctly on its own?
You may need to change the $record_directory to an absolute path (‘http://www.something.com/test_folder/’) instead of a relative path - but if that is the case, it should have been a problem with the script when you ran it by itself too.
I am not seeing how combining the scripts this way would have changed anything…
Let’s divide this script into two
This code create issueless folders of links.
[php]<?php
function readUrls()
{
// Reads links from a file
$read_dir="./";
$read_file=“dizin_dosya_linkleri.txt”;
$connect_to_red=@fopen ("$read_dir/$read_file",‘r’);
if(!$connect_to_red)
{
echo “could not open database”;
exit();
}
while(!feof($connect_to_red))
{
$read=fgets($connect_to_red,4096);
$url[] = $read;
}
@fclose($connect_to_red);
return $url;
}
function makeFolders($url)
{
// Creates folders of Links
if(is_array($url) && !empty($url))
foreach($url as $url_new)
{
$path = explode(’/’,dirname($url_new),4);
$dirspath = array(’./’.$path[count($path)-1].’/’);
$dirspath2 = array($path[count($path)-1]);
for($i=0;$i<count($dirspath);$i++)
{
if (!file_exists($dirspath[$i])){
$fullDir = $dirspath[$i];
exec("mkdir -p ".$fullDir);
}
$dirs=explode("/",$fullDir);
$currentFolder='';
for($x=0;$x<count($dirs);$x++)
{
$currentFolder.=$dirs[$x].'/';
if(!is_dir($currentFolder))
{
echo "Created: $currentFolder <br/>";
if(!mkdir($currentFolder))
{
die("Could not make ".$currentFolder);
}
}
}
}
}
}
$urls = readUrls();
makeFolders($urls);
?>[/php]
Now let’s do the second code
The following code works fine. But, not read from a file, the path is automatically not determine.
This code will move the files by assigning automatically paths of files that the code will move, to this code after reading the links from the file.
[php]
-
<?php
// Moved files of Links
$url = array(
'http://www.domain.com/file.php',
'http://www.domain.com/dir1-1/dir2/dir3/file.jpg',
'http://www.domain.com/dir1-2/dir2/dir3/dir4/file.zip',
'http://www.domain.com/dir1-3/dir2/dir3/dir4/dir5/file.gif',
'http://www.domain.com/dir1-4/dir2/dir3/dir4/dir5/dir6/file.png',
'http://www.domain.com/dir1-5/dir2/dir3/dir4/dir5/dir6/dir7/file.rar',
);
$record_directory = './test_folder/';
for($i=0;$i<count($url);$i++){
$file_name = basename($url[$i]);
if(copy($url[$i],$record_directory.$file_name)){
echo '
-
File Uploaded: ';
echo $file_name;
echo '
';
}else{
echo ' - error '; } } ?>
Best Regards.
Thank you
Reply #18 codes
Here’s the error in this
screen image
line 63 “if(copy($url[$i],$record_directory.$file_name))”
http://d1209.hizliresim.com/11/t/dcksp.png
My sample Links “links_data.txt”
http://www.ciceksehri.com/wp-content/uploads/2011/03/5888cicek6.jpg http://www.hediyecicek.com.stabilisim.com/r/buyuk_urun_resimi/3222.jpg http://www.ciceksehri.com/wp-content/uploads/2011/03/cicek_0011.jpg http://www.ciceksehri.com/wp-content/uploads/2010/11/kirmizi-pueskuellue-cicek-resmi.jpg http://www.cicekresimleri.org/data/media/72/masaustucicekresimleri3.jpg http://www.baylar.net/cicek_resimleri/cicekresimleri13.jpg
Best Regards
I have looked this over again. Was the part that is failing working before merging the three scripts? And was it working with the exact same array of links that you used in the first two?
This code works, but not with array
[php]
-
<?php
// Moved files of Links
$url = array(
'http://www.ciceksehri.com/wp-content/uploads/2011/03/5888cicek6.jpg',
'http://www.hediyecicek.com.stabilisim.com/r/buyuk_urun_resimi/3222.jpg',
'http://www.ciceksehri.com/wp-content/uploads/2011/03/cicek_0011.jpg',
'http://www.ciceksehri.com/wp-content/uploads/2010/11/kirmizi-pueskuellue-cicek-resmi.jpg',
'http://www.cicekresimleri.org/data/media/72/masaustucicekresimleri3.jpg',
'http://www.baylar.net/cicek_resimleri/cicekresimleri13.jpg',
);
$record_directory = './test_folder/';
for($i=0;$i<count($url);$i++){
$file_name = basename($url[$i]);
if(copy($url[$i],$record_directory.$file_name)){
echo '
-
File Uploaded: ';
echo $file_name;
echo '
';
}else{
echo ' - error '; } } ?>
Output
[ol][li]File Uploaded: 5888cicek6.jpg
File Uploaded: 3222.jpg
File Uploaded: cicek_0011.jpg
File Uploaded: kirmizi-pueskuellue-cicek-resmi.jpg
File Uploaded: masaustucicekresimleri3.jpg
File Uploaded: cicekresimleri13.jpg[/li]
[li][/li][/ol]
Thanks
but not with arrayEDIT: from the file "links_data.txt" does not work
Is there a different file with the links for this section of code that you would like to have it parse? It is going to have to get the links from somewhere.
Hi,
All files are attached, HERE: http://www.ardeseni.com/all_scripts.zip
you can run the file, No another file
Thank you very much for your help again
I downloaded the files and looked at them.
Here is my question: Originally we were looking at three different scripts:
[ol][li]Read links from a text file[/li]
[li]Create folders from the links[/li]
[li]Move the files[/li][/ol]
Am I correct that when you run each script on its own, it works fine?
Am I correct that the text file that contains the links is the exact same file and links for all of the scripts?
The only difference between the combined scripts is that it loads the links once and uses the exact same links for all three functions. If the same links are not meant to be used in all three scripts, I need to know exactly how to get the links for each section.
The only problem with this place is (Move the files)
I want this “Move each file cat folder”
My code is unable to do so
Thanks
No, it does not work as I want
Yes, same
It does not matter to make the entire process with a single script.
- script : I created folders after the following your script read links from “links_data.txt”
2.script: to move each file to its own folder, after read links from the same “links_data.txt”
Now I need these 2 script
You can disregard.
The important thing is to move each file to its own folder.
Again thanks
[php]<?php
function readUrls()
{
// Reads links from a file
$read_dir="./";
$read_file=“links_data.txt”;
$connect_to_red=@fopen ("$read_dir/$read_file",‘r’);
if(!$connect_to_red)
{
echo “could not open database”;
exit();
}
while(!feof($connect_to_red))
{
$read=fgets($connect_to_red,5120);
$url[] = $read;
}
@fclose($connect_to_red);
return $url;
}
function makeFolders($url)
{
// Creates folders of Links
if(is_array($url) && !empty($url))
foreach($url as $url_new)
{
$path = explode(’/’,dirname($url_new),4);
$dirspath = array(’./’.$path[count($path)-1].’/’);
$dirspath2 = array($path[count($path)-1]);
for($i=0;$i<count($dirspath);$i++)
{
if (!file_exists($dirspath[$i])){
$fullDir = $dirspath[$i];
exec("mkdir -p ".$fullDir);
}
$dirs=explode("/",$fullDir);
$currentFolder='';
for($x=0;$x<count($dirs);$x++)
{
$currentFolder.=$dirs[$x].'/';
if(!is_dir($currentFolder))
{
echo "<b>Created:</b> $currentFolder <br/>";
if(!mkdir($currentFolder))
{
die("Could not make ".$currentFolder);
}
}
}
}
}
}
$urls = readUrls();
makeFolders($urls);
?>[/php]
Hello,
First, I created folders of links by using the above code.
Then, Each file has been loaded in its own folder without any problem.
Now, I just want that the code reads from the file.
[php]
-
<?php
// Moved files of Links
$url = array(
'http://www.muttafi.com/customavatars/avatar268_18.gif',
'http://www.muttafi.com/customavatars/thumbs/avatar441_7.gif',
'http://www.muttafi.com/images/regimage/backgrounds/background9.jpg',
'http://www.muttafi.com/images/ads/locator/ad_global.jpg',
'http://www.muttafi.com/album/images/253/medium/1_arazimiz.jpg',
'http://www.muttafi.com/album/images/253/1_manzara.jpg',
'http://www.muttafi.com/album/images/92/2_PIC_0016.JPG',
'http://www.muttafi.com/album/images/92/medium/2_PIC_0023.JPG',
'http://www.muttafi.com/album/images/484/small/7_okull.JPG',
'http://www.muttafi.com/album/images/68/small/1_DSC01291.jpg',
);
for($i=0;$i<count($url);$i++){
$path = explode('/',dirname($url[$i]),4);
$record_directory = './'.$path[3].'/';
//echo $record_directory;
$file_name = basename($url[$i]);
//echo $record_directory;
if(copy($url[$i],$record_directory.$file_name)){
echo '
-
File Uploaded: ';
echo $file_name;
echo '
';
}else{
echo ' - error '; } } ?>
Only one problem left.
Thank you
Hi @malasho,
Thank you very much
I added “trim()” and the problem has solved.
$url[] = $read;
$url[] = trim($read);
Glad to hear it!
I have marked this thread solved. Best to you.
jay
Your again very very thank you