Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,151,047 members, 7,810,869 topics. Date: Saturday, 27 April 2024 at 05:24 PM

Convert This To Php - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Convert This To Php (1161 Views)

An Introduction To PHP - Beginners Base / How To Connect Vb.net Windows Application To Php And My Sql Database / Help me convert this Vb6.0 code To Vb.net (2) (3) (4)

(1) (Reply) (Go Down)

Convert This To Php by luckyCO(m): 5:31pm On Jul 08, 2009
Am writing a program that requires sending files to the net automatically.
The program can use dot and php where applicable.

I hv done that in dotnet which is my.computer.network.upload(Filename,Destination,user name,password)

All the php code i see didnot allow me the call a php page and specify a filename and it will upload it for me.

I have used this but wasnt working why?

<?php

$target=$_POST['filename'];
$destination=$_POST['filepath'];


$result = move_uploaded_file($target, $destination);

?>

Please help me make the code in this format.

Thanks
Re: Convert This To Php by lojik(m): 9:43am On Jul 09, 2009
if the file is uploaded from a form with filefield name=userfile and submitted to php page, use this code:

//upload file
if(isset($_POST['upload']))
{
$fileName = $_FILES['userfile']['name']; //get original filename
$tmpName = $_FILES['userfile']['tmp_name']; //get the name used to store the file on server temporarily

$result = move_uploaded_file($tmpName, $destinationdir.'/'.$fileName);
if (!$result) {
echo "Error uploading file";
exit;
}
}

Otherwise, if uyou are just moving files from one path to the other on ur server
if ( !copy($target, $destination) ) {
echo "failed to copy $target, <br>\n";
}
Re: Convert This To Php by luckyCO(m): 4:33pm On Jul 09, 2009
Thanks for your honest answer.
I really don't need human interference. I want everything done automatically; selecting file and clicking upload button.

The code above still needs me to click browse and Upload button.

I want to use code to specify the filename and code again to upload it.

Can you help?
Re: Convert This To Php by lojik(m): 10:01pm On Jul 09, 2009
Is the file resident on a client machine or on the system running the php server?
is the file going to be changing per time, per client system or what?

you might need to supply more info to get more info.
Re: Convert This To Php by luckyCO(m): 10:48am On Jul 11, 2009
lojik:

Is the file resident on a client machine or on the system running the php server?
is the file going to be changing per time, per client system or what?

you might need to supply more info to get more info.

The files is resident on client machine, and I would like to be moving them gradually to the net each time file occur on the client machine.
I dont need human intervention, I need this to be done at the backend ,can u assist me now?
Re: Convert This To Php by Nobody: 7:55pm On Jul 11, 2009
maybe you need php-gtk or python or some other language to be installed on the said client machine.

your web browser wont give you that permission, javascript wont even help you.
except u have admin access to the client computer.
Re: Convert This To Php by ThePhantom(m): 10:24am On Jul 12, 2009
I am not sure what you are trying to upload, but Php is not the programming language to use. You are trying to upload a file from a Client Pc to the Web, use C++ or VB to write an app that will run in the back ground and scan for the file. When the file is detected the app uses FTP to upload the file or if you want you can use the app to launch a PHP page at your URL that will pull the file.
Re: Convert This To Php by 2010(f): 11:21am On Jul 12, 2009
u definitely need a client-side.
if u cant code it, u can down load a sync application that runs on d client pc, watches his folder and does a one way sync to a remote folder via ftp. i think i saw something like that on softpedia.com once.
Re: Convert This To Php by lojik(m): 8:34am On Jul 13, 2009
if u can, code a clientside that listens or watches the folder and uploads the files when they are present. if u cant, mail me: lekeojikutu@yahoo.com for further assistance.
Re: Convert This To Php by luckyCO(m): 4:29pm On Jul 13, 2009
ThePhantom:

I am not sure what you are trying to upload, but Php is not the programming language to use. You are trying to upload a file from a Client Pc to the Web, use C++ or VB to write an app that will run in the back ground and scan for the file. When the file is detected the app uses FTP to upload the file or if you want you can use the app to launch a PHP page at your URL that will pull the file.

Yes Am coding with dotnet
I need a script to call using the dot that will know when I send the file
the code below works very well with Dotnet but I want similar thing in php since am hosting in php site and can install aspx there to use;

Dim f As String
Dim file
For Each f In Request.Files.AllKeys
file = Request.Files(f)
file.SaveAs("C:\Inetpub\wwwroot\products\" & file.FileName)
Next f

Can anyone help me convert the code above to php

Or if I convert the file to byte is there anyway where php can reconvert it as file and save it for me?
I need help urgently
Re: Convert This To Php by luckyCO(m): 4:36pm On Jul 13, 2009
lojik:

Is the file resident on a client machine or on the system running the php server?
is the file going to be changing per time, per client system or what?

you might need to supply more info to get more info.

Watching the folder is not my problem, my problem is to tranfer it automatically from my pc to the net using php or any script that run on php hostable server.

If you have written such please let me have,all code I saw must personally have to click browse and locate the folder.

I want to code all what happened when one click browse and upload button, what php script will do for me to know the file I sent with name and save it for me just like the dotnet has done.
Re: Convert This To Php by lojik(m): 9:26pm On Jul 13, 2009
<?php
//receive file data sent to page
$binary_content=$_REQUEST['binary_Jpeg_or_other_Unicode_File_From_Client_App'];

$fp = fopen('data.jpg', 'w');
fwrite($fp, $binary_content);
fclose($fp);

// 'data.jpg' is now a jpeg picture!
?>

for a better understanding, visit http://us2.php.net/manual/en/function.fwrite.php . i've never used this code but i know it should work if your client application sends the file as a binary file to the php page on your server.
Re: Convert This To Php by luckyCO(m): 9:58am On Jul 14, 2009
lojik:

<?php
//receive file data sent to page
$binary_content=$_REQUEST['binary_Jpeg_or_other_Unicode_File_From_Client_App'];

$fp = fopen('data.jpg', 'w');
fwrite($fp, $binary_content);
fclose($fp);

// 'data.jpg' is now a jpeg picture!
?>

for a better understanding, visit http://us2.php.net/manual/en/function.fwrite.php . i've never used this code but i know it should work if your client application sends the file as a binary file to the php page on your server.

In sending to say upload.php how will I pass the binary code (binary_Jpeg_or_other_Unicode_File_From_Client_App)?

Will Code is this way http://localhost/upload.php?binary_Jpeg=the byte conversion of the file?
Or do I need to hide it somewhere since byte is not a string?
Re: Convert This To Php by lojik(m): 5:56pm On Jul 14, 2009
for a small clientside like this, i'd have used Flash + MDM Zinc (Rapid Application Development Platform for flash).

MDM Script has the command :
mdm.FileSystem.loadFileUnicode("file_path"wink;

that makes it possible for me to load a file in unicode mode. I'd use zinc because i have Zinc license. Ur prog. language shd have something like this.

to read a file like this in php, i'd use: file_get_contents('image_path');

I guess dot net guys in d forum can help u out. u can also upload to a remote folder directly without sending to php file (use FTP. In MDM Script i'd use:
myFTP.sendFile("C:\\myLocalFile.txt", "myRemoteFile.txt"wink;
Re: Convert This To Php by Nobody: 11:58pm On Jul 14, 2009
i see, u need a way to receive the transferred file.

lojik's code shud work, just that you may need to modify

$fp = fopen('data.jpg', 'w');
to
$fp = fopen('data.jpg', 'wb');

since it is binary, that makes it cross platform compatible

(1) (Reply)

Java And Biometrics / Power Monitor Lite - PC App / A Teaching GIG For ROR Developers And Web Developers

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 32
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.