PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, November 13, 2022

[FIXED] How to write a file ussing PHP schedule task in PLESK ?

 November 13, 2022     cron, php, plesk     No comments   

Issue

I am trying to write a file in my VPS server. I am using a simple script who works perfectly in my localhost, but not running as PLESK scheduled task.

PHP scripts is as follows

<?php
$fileUrl = 'http://xxxxremotefile.kml';
$saveTo = 'myfile.kml';

$fp = fopen($saveTo, 'w+');
if($fp === false){
    throw new Exception('Could not open: ' . $saveTo);
}
$ch = curl_init($fileUrl);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_exec($ch);
if(curl_errno($ch)){
    throw new Exception(curl_error($ch));
}
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($statusCode == 200){
    echo 'Downloaded!';
} else{
    echo "Status Code: " . $statusCode;
}
?>

The script runs. No error, but no file writed.

What am I doing wrong?


Solution

Can you set absolute path for the $saveTo and check ? Example,

$saveTo = '/home/myfile.kml';


Answered By - Iynga Iyngaran Iyathurai
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing