LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-28-2008, 09:26 AM   #1
tanoatlq
Member
 
Registered: Mar 2007
Posts: 157

Rep: Reputation: 30
php upload give me some problems


Hello,
I make a simple php upload approach that launches shell
scripts on the server with the a file provided by the client.
On the client machine, the progress bar that should shows the
reloading status of the page never reaches the end.
However, the commands launched by php works.

I try to set these commands to work in the background as

system("/usr/bin/sudo -u myuser script.sh &");

but the problem persists. I am new of php language, and I would
like to know what sort of things could make this solution defects.
I try with flush(), but no way.
What could be that cannot make me sleep?
 
Old 04-29-2008, 03:05 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Hi

I've had similar problems - and I remember I played with nohup and redirecting output. I got it to work somehow, but it was not stable. I think it's because the command's output is supposed to go to the browser, and that can be tricky when the browser is gone.

But I found one solution in the end. Instead of outputting progress to stdout, I just output the progress to a text file. To get the process to run independent of the web-server (so you can even restart the webserver while the script is running), I used the at command.

PHP Code:
$cmd "/usr/bin/sudo -u myuser script.sh &>/dev/null";
$cmd "echo ".EscapeShellArg($cmd)." | at now";
exec($cmd); 
Then I just read the progress file and output it to the browser. The client can then reload the page to see how it's going, or you could make it auto-reload with a meta tag every now and then.

You probably have to add www-data to /etc/at.allow or remove it from /etc/at.deny for it to work.
 
Old 04-29-2008, 06:28 AM   #3
tanoatlq
Member
 
Registered: Mar 2007
Posts: 157

Original Poster
Rep: Reputation: 30
In my case the script.sh launch openoffice that should run in loop.
I will try the at tip. However I would like to know if less tricky solutions exists.
It seems a terrible hack! How could you think it? :-)
 
Old 04-30-2008, 08:15 AM   #4
tanoatlq
Member
 
Registered: Mar 2007
Posts: 157

Original Poster
Rep: Reputation: 30
Hey, it appears to work fine!
I am testing the robustiness of my php code, and I would
like to know what could I do when the user upload a file
that does not exist in the local machine..
move_uploaded_file() does not handle this case correctly..
 
Old 04-30-2008, 04:28 PM   #5
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
I can't exactly remember but doesn't that just give you a new file of size zero? In which case look at the size of the file.
 
Old 05-01-2008, 04:38 AM   #6
tanoatlq
Member
 
Registered: Mar 2007
Posts: 157

Original Poster
Rep: Reputation: 30
It could be. However I though that any function that does this work more specifically
should exists.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP upload logging? FirmbIT Linux - General 1 12-14-2005 01:44 PM
Php Upload Files rabee77 Linux - Software 1 01-16-2005 05:26 AM
Upload Script....but not php vous Programming 1 02-04-2004 02:13 PM
PHP/HTTP hile upload problems... markstevens Linux - Networking 2 06-19-2003 10:16 AM
ftp upload in php raven Programming 2 07-07-2002 05:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration