Failed to open stream: No such file or directory

sabari k

I want to copy selected image file one folder into another folder. Image selection process is dynamically. i am using below php code for copy process.

//$cnt is count of selected images

for($i=0;$i<$cnt;$i++)
    {
    $img = $sel['album_images']; //name of file to be copied
                //read the file
                $fp = fopen('uploads/members/album/'.$_SESSION['ses_userid'].'/'.$img, 'r') or die("Could not contact $img");
                $page_contents = "";
                while ($new_text = fread($fp, 100)) 
                {               
                $page_contents .= $new_text;
                }
                chdir("uploads/products/design/"); //This moves you from the current directory user to the images directory in the new user's directory
                $newfile = "product-".strtotime('now').".png"; //name of your new file
                //create new file and write what you read from old file into it
                $fd = fopen($newfile, 'w');
                fwrite($fd, $page_contents);
                fclose ($fd);
}

The above code is run perfectly for if the selected image count is 1.but it produce the error if the selected image count above 1.

Error is : 

Warning: fopen(uploads/members/album/72/full_e5829jellyfish.jpg) [function.fopen]: failed to open stream: No such file or directory in D:\wamp\www\myprint\photoprint_step2.php on line 51
    Could not contact full_e5829jellyfish.jpg

Note : If the selected image count is 2 then the first image will be copied successfully , next (2nd image) the error will be produced. What happened?

pedrouan

I assume that your for-cycle causes the errors, as you change your directory just once (and not change it back) and in the second and later iterations, you don't.

I wouldn't use chdir function, for cleanliness and readability of the code, it's better to use full paths.

$newfile = "uploads/products/design/product-".strtotime('now').".png";

Be aware of using strtotime('now') as the only indentificator of your image file, as many images could be saved within one second, and that can be your case. That's why your image has the same name in the second iteration, it saves the content of the second image, but replaces the previous one.

Try to put some random constant in it, like this

$newfile = "uploads/products/design/product-".strtotime('now')."-".rand(1000,9999).".png";

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

PHP - Failed to open stream : No such file or directory

From Java

failed to open stream: No such file or directory (Laravel)

From Dev

file_get_contents() failed to open stream: No such file or directory

From Dev

Warning: include(PHPExcel.php): failed to open stream: No such file or directory

From Dev

SplFileObject error failed to open stream: No such file or directory

From Dev

autoload.php issue: failed to open stream: no such file or directory

From Dev

Failed to open stream: No such file of directory in... PHP fopen

From Dev

php artisan migrate:reset failed to open stream: No such file or directory

From Dev

failed to open stream: No such file or directory (but files are in the correct location)

From Dev

File exists but PHP throwing "failed to open stream: no such file or directory"

From Dev

app/bootstrap.php.cache : failed to open stream: No such file or directory

From Dev

Laravel classloader.php error failed to open stream: No such file or directory

From Dev

file_get_contents(): failed to open stream: No such file or directory

From Dev

move_uploaded_file(...): failed to open stream: No such file or directory

From Dev

Zend include_once(myphpfile): failed to open stream: No such file or directory

From Dev

PHPUnit error "Failed to open stream: No such file or directory"

From Dev

File upload on s3 : failed to open stream: No such file or directory

From Dev

Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0

From Dev

PHP - failed to open stream: No such file or directory in

From Dev

yii PDO.php error: failed to open stream: No such file or directory

From Dev

File exists but PHP throwing "failed to open stream: no such file or directory"

From Dev

file exists but fopen "failed to open stream no such file or directory"

From Dev

file_get_contents(): failed to open stream: No such file or directory

From Dev

Warning: include(dbconn.php): failed to open stream: No such file or directory

From Dev

Failed to open stream: No such file or directory in...? PHP Specific

From Dev

Zend include_once(myphpfile): failed to open stream: No such file or directory

From Dev

PHP/SQL - failed to open stream: No such file or directory

From Dev

failed to open stream: No such file or directory

From Dev

failed to open stream: No such file or directory issue

Related Related

  1. 1

    PHP - Failed to open stream : No such file or directory

  2. 2

    failed to open stream: No such file or directory (Laravel)

  3. 3

    file_get_contents() failed to open stream: No such file or directory

  4. 4

    Warning: include(PHPExcel.php): failed to open stream: No such file or directory

  5. 5

    SplFileObject error failed to open stream: No such file or directory

  6. 6

    autoload.php issue: failed to open stream: no such file or directory

  7. 7

    Failed to open stream: No such file of directory in... PHP fopen

  8. 8

    php artisan migrate:reset failed to open stream: No such file or directory

  9. 9

    failed to open stream: No such file or directory (but files are in the correct location)

  10. 10

    File exists but PHP throwing "failed to open stream: no such file or directory"

  11. 11

    app/bootstrap.php.cache : failed to open stream: No such file or directory

  12. 12

    Laravel classloader.php error failed to open stream: No such file or directory

  13. 13

    file_get_contents(): failed to open stream: No such file or directory

  14. 14

    move_uploaded_file(...): failed to open stream: No such file or directory

  15. 15

    Zend include_once(myphpfile): failed to open stream: No such file or directory

  16. 16

    PHPUnit error "Failed to open stream: No such file or directory"

  17. 17

    File upload on s3 : failed to open stream: No such file or directory

  18. 18

    Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0

  19. 19

    PHP - failed to open stream: No such file or directory in

  20. 20

    yii PDO.php error: failed to open stream: No such file or directory

  21. 21

    File exists but PHP throwing "failed to open stream: no such file or directory"

  22. 22

    file exists but fopen "failed to open stream no such file or directory"

  23. 23

    file_get_contents(): failed to open stream: No such file or directory

  24. 24

    Warning: include(dbconn.php): failed to open stream: No such file or directory

  25. 25

    Failed to open stream: No such file or directory in...? PHP Specific

  26. 26

    Zend include_once(myphpfile): failed to open stream: No such file or directory

  27. 27

    PHP/SQL - failed to open stream: No such file or directory

  28. 28

    failed to open stream: No such file or directory

  29. 29

    failed to open stream: No such file or directory issue

HotTag

Archive