You are not logged in.

#1 2010-11-12 14:51:58

awak3
Member
Registered: 2010-08-02
Posts: 4

PHP - rename() no such file or directory

Hello dear Archers,

iam actually writing a little rename-script that changes my picturenames and the associated database entrys of those.

So i got this problem by running it:

Warning: rename(Users/tobiasz/Sites/convertpics/New_2_18_2386506_1.jpg,Users/tobiasz/Sites/convertpics/1.jpg) [function.rename]: No such file or directory in /Users/tobiasz/Sites/picturerenamer_beta.php on line 44

here is the relevant code(i know its not that clean,sry for that):

for($id=1; $id<230; $id++) {

        $result = mysql_query("SELECT picture FROM sms_profiles WHERE id='".$id."'");
        $output = mysql_fetch_array($result);
        
        $pic = $output['picture'];
        $picrdy = "$pic.jpg";
        $idrdy = "$id.jpg";
         
        $renamea = "/convertpics/".$pic."";
        $renameb = "/convertpics/".$idrdy."";
        rename($renamea, $renameb);
        $change = "UPDATE sms_profiles SET picture='".$idrdy."' WHERE id='".$id."'";
    }

i tried to change directorys, gave all files and directorys full permisions and and and.. its 3hours now iam on it.. thanks for help!

Offline

#2 2010-11-12 18:41:42

whatshisname
Member
Registered: 2010-04-24
Posts: 163

Re: PHP - rename() no such file or directory

awak3 wrote:

Hello dear Archers,

iam actually writing a little rename-script that changes my picturenames and the associated database entrys of those.

So i got this problem by running it:

Warning: rename(Users/tobiasz/Sites/convertpics/New_2_18_2386506_1.jpg,Users/tobiasz/Sites/convertpics/1.jpg) [function.rename]: No such file or directory in /Users/tobiasz/Sites/picturerenamer_beta.php on line 44

here is the relevant code(i know its not that clean,sry for that):

for($id=1; $id<230; $id++) {

        $result = mysql_query("SELECT picture FROM sms_profiles WHERE id='".$id."'");
        $output = mysql_fetch_array($result);
        
        $pic = $output['picture'];
        $picrdy = "$pic.jpg";
        $idrdy = "$id.jpg";
         
        $renamea = "/convertpics/".$pic."";
        $renameb = "/convertpics/".$idrdy."";
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This command/variable declaration is looking for the "convertpics" folder in the root directory.

I doubt that's what you're trying to do.

Give the full path to where "convertpics" is.  i.e., /home/yourusername/convertipics, and try again.



        rename($renamea, $renameb);
        $change = "UPDATE sms_profiles SET picture='".$idrdy."' WHERE id='".$id."'";
    }

i tried to change directorys, gave all files and directorys full permisions and and and.. its 3hours now iam on it.. thanks for help!

Offline

#3 2010-11-15 12:23:04

awak3
Member
Registered: 2010-08-02
Posts: 4

Re: PHP - rename() no such file or directory

still same error. all files and folders are 777.

Offline

#4 2010-11-15 14:57:46

whatshisname
Member
Registered: 2010-04-24
Posts: 163

Re: PHP - rename() no such file or directory

awak3 wrote:

still same error. all files and folders are 777.

So this is the error:

> Warning: rename(Users/tobiasz/Sites/convertpics/New_2_18_2386506_1.jpg,Users/tobiasz/Sites/convertpics/1.jpg) [function.rename]: No such file or directory in /Users/tobiasz/Sites/picturerenamer_beta.php on line 44

And you say you're getting the "same" error?

OK. The "rename" function error says it can't find the file. 

Note the lack of a leading slash in: "rename(Users/tobiasz/Sites/convertpics/New_2_18_2386506_1.jpg".  So it's looking for a relative path and not an absolute path.

Without actually running the script, I would have thought:

$renamea = "/Users/tobiasz/Sites/convertpics/".$pic."";
$renameb = "/Users/tobiasz/Sites/".$idrdy."";

would have worked. 

This is assuming "Users" is in the root folder of the file-system, and not the document root of the web server.  (I can't tell whether you're running the php script under Apache or as a command line script.)

If "Users" is not in the root folder of the file-system, then give the full path to it from the root of the file-system when you declare "$renamea":  i.e.,

$renamea = "/home/Users/tobiasz/Sites/convertpics/".$pic."";

or something like that.

If that doesn't work, please post the error message again.  And let us know whether you're running this as a web script or a command-line script.

Good luck.

Offline

#5 2010-11-15 15:33:43

awak3
Member
Registered: 2010-08-02
Posts: 4

Re: PHP - rename() no such file or directory

Hi, thanks for your effort!

Here is my actual script

for($id=1; $id<140; $id++) {

        $result2 = mysql_query("SELECT picture FROM sms_profiles WHERE id='".$id."'");
        $output = mysql_fetch_array($result2);
        
        $pic2trim = $output['picture'];
        $pic = trim($pic2trim);
        $picrdy = "$pic.jpg";
        $idrdy = "$id.jpg";
         
        $renamea1 = "/var/www/".$pic."";
        $renameb1 = "/var/www/".$idrdy."";
       /* echo "<b>";
        echo $renamea1;
        echo "</b>";
      */$renamea2 = trim($renamea1);
        $renameb2 = trim($renameb1);
        rename($renamea2, $renameb2);
        $change = "UPDATE sms_profiles SET picture='".$idrdy."' WHERE id='".$id."'";
        echo "<br>";
    }

Iam working on a linux machine now. The problem still exists.

thats the echo--->     New_2_20_2148064_1.jpg

Warning: rename(/var/www/New_2_18_2386506_1.jpg,/var/www/1.jpg): No such file or directory in /var/www/picturerenamer_beta.php on line 60

I tried to change the paths in "./var/www/" in "var/www/" in "/var/www/convertpics/" etc.
Also i have created a small script to try it in a easier way:

$a = "/var/www/convertpics/a.jpg";
$b =trim($a);
echo $b;
    rename($b, '/var/www/d.jpg');

AND THIS ACTUALLY WORKED! I unnamed a file by hand to a.jpg and run this script.
Is it a MySQL problem? Iam really confused right now and after 6hours sitting on that, iam rly out of power either. big_smile

Offline

#6 2010-11-17 03:22:38

action_owl
Member
From: WWW, The Internet 127.0.0.1
Registered: 2009-08-15
Posts: 73

Re: PHP - rename() no such file or directory

awak3,
Can you post a sample of what your `sms_profiles`  table looks like? You definetly don't need to make 140+ queries...

This should work for you but I just wrote it on the fly so look over it first...

<?php

/**
* Assuming the following structure of sms_profiles
* and that you're trying to rename "somePicA.jpg" on the filesystem to "1.jpg"
*
* id   picture
* --   -------
*  1   somePicA
*  2   somePicB
*  3   somePicEtc
*/    

$result = mysql_query("select picture, id from sms_profiles where id <= 140 order by id");

while($row=mysql_fetch_array($result,MYSQL_ASSOC))
{
     rename("/var/www/{$row['picture']}.jpg", "/var/www/{$row['id']}.jpg");
     $sqlString .= "(update sms_profiles set picture='{$row['id']}.jpg' where id={$row['id']});\n";
}

// you should then also be able to execute "$sqlString" and update your table
mysql_query($sqlString);

?>

Last edited by action_owl (2010-11-17 03:47:33)

Offline

Board footer

Powered by FluxBB