views:

1074

answers:

6

Guys I need ur help,

I have a text file which contains a text like "c:/images/myimage.jpg"

Now using PHP I want to move this local image file to somewhere on server. Is it possible?

Please suggest!

Thanks,

Jaswant

A: 

Do the following:

move_uploaded_file($file, $directory);

See here form more info

Rigobert Song
ah, sorry misread the question!
Rigobert Song
+1  A: 

You could try to use cURL to read the file and store that data into the server.

But this only works if this file is on the server.

$ch = curl_init("file://c:/images/myimage.jpg");
$fp = fopen("myimage.jpg", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);
Ólafur Waage
+1  A: 

If the server has no way to let you upload files, then a program (written in PHP or otherwise) has no interface that it can use to upload files.

So, no, it isn't possible.

David Dorward
+3  A: 

jaswanttak, If you want you web page to move the file from the user’s computer, this is not possible. Otherwise any webpage would be able to take any of your files without you even knowing it!

If you just use PHP to mess with files and want to copy a file to a connected server (let’s say it’s assigned a drive letter S:), then you can use function like copy ('c:\images\myimage.jpg', 's:\some\path\myimage.jpg'), given that you have writet access there. But I don’t think this is what you meant :-)

Ilya Birman
A: 

Guys,

Thanks a lot for your time,

  1. move_uploaded_file() will not work here coz I m not using the upload functionality as it requires the temp_name of the file being uploaded.

  2. copy() function of PHP will not work as I think coz it just copies the files on server. i.e. the source and target file both should be on server.

  3. No idea about CURL.

jaswanttak
+1  A: 

You cannot access files on a users computer from your server without any kind of client-side software/a file upload box/flash component/etc running in the users browser.

They will have to initiate the upload in many cases, although you could help them by telling them which file to upload after reading the text in the "text file" they've uploaded?

Marineio