Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8178119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:41:14+00:00 2026-06-06T23:41:14+00:00

I have wrote a PHP file which will save a JPEG file in the

  • 0

I have wrote a PHP file which will save a JPEG file in the server and part of the code is listed as follow:

    //create folder if folder not exist
if (!is_dir($save_path)){

    $old = umask(0);
    $flag = @mkdir($save_path,0777);
    umask($old); 

if(isset($flag)){
    $string = 'Folder Create Success!'."\n";
}else{
    $string= 'Folder Create Fail!'."\n";
}
echo $string;

}else{

   echo "Folder exist!!!!";

}


//write the content to the server
$base=$_REQUEST['image'];
$binary=base64_decode($base);
header('Content-Type: image/jpg; charset=utf-8');

if(!$file = fopen($path, 'wb')){

    echo 'Image upload Fail!'."\n";
    return;
}
else
{

    fwrite($file, $binary);
    fclose($file);

}

The problem is when I run the code, if the folder does not exist, it create the folder only but the content can’t save in the folder. The error message is :

[Thu Jul 05 16:59:06 2012] [error] [client 10.95.61.220] PHP Warning: fopen(/mnt/csis/upload/newphoto/others/12346_test/12346_test_2012-07-05_others_abc.jpg): failed to open stream: Permission denied in /var/www/html/upload_image.php on line 57

However, if I run the code again, since the folder was created in the past, it work properly. The content can save in the folder……

Anything I get wrong? I try to find the answer on the web but still can’t solve the problem.

Anyone can help, many thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T23:41:15+00:00Added an answer on June 6, 2026 at 11:41 pm

    I would try changing the creation of the folder to use the recursive flag:

    $flag = @mkdir($save_path . "/" . $file,0777,true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok. I have my query written finally for my php file (which will write
I write app on android which will send xml file to PHP server. Here
I have a single PHP file which handles credit card processing. It starts as
I have found this code to make php file cache and compress. Below is
I want to HTTP POST data to a PHP file which will in-turn write
I have a PHP file which writes some information into a configuration file which
In my .htaccess file i have the following re-write rule RewriteRule ^([a-z]*)$ work.php?album=$1 [L]
I have a blog I wrote in PHP, and need to shorten the latest
I have wrote a script to detect when I reach the div element which
I have wrote some code to find out of 3 variables witch is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.