Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Uploading files from URL and other functions - HELP!
Old 12-05-2007, 10:32 PM Uploading files from URL and other functions - HELP!
The PHP Professor

Posts: 340
Name: Alex
Location: Behind You
Trades: 0
I want to get a file from a url and copy it to a directory on my server. Not only that but i want to be able to get the file size of the actual file before it is really copied to my server.

I know about the Copy() function but how would i get a the file size or type before the script actually puts it on my server? This would be useful if i did not want people to upload .html files and such.

Thanks in advance!
__________________
Go Kirby! <(" . "<) (^" . "^) (>" . ")> Talkupation!
microcolt is offline
Reply With Quote
View Public Profile Visit microcolt's homepage!
 
 
Register now for full access!
Old 12-06-2007, 02:08 AM Re: Uploading files from URL and other functions - HELP!
Harlequin's Avatar
Extreme Talker

Posts: 166
Name: Mick
Location: Tenerife
Trades: 0
Micro

here ya go:
http://www.php.net/manual/en/function.file.php

and...
http://www.php.net/manual/en/function.filesize.php
__________________

Please login or register to view this content. Registration is FREE

Death Once Had a Near Harlequin Experience...!
Harlequin is offline
Reply With Quote
View Public Profile Visit Harlequin's homepage!
 
Old 12-06-2007, 09:25 PM Re: Uploading files from URL and other functions - HELP!
The PHP Professor

Posts: 340
Name: Alex
Location: Behind You
Trades: 0
Thanks but can you give me a script example, i dont really get it.
__________________
Go Kirby! <(" . "<) (^" . "^) (>" . ")> Talkupation!
microcolt is offline
Reply With Quote
View Public Profile Visit microcolt's homepage!
 
Old 12-07-2007, 10:56 AM Re: Uploading files from URL and other functions - HELP!
shivaji's Avatar
Ultra Talker

Posts: 321
Trades: 0
http://www.frihost.com/users/sonam/blog/vp-82594.html

Shivaji
__________________

Please login or register to view this content. Registration is FREE
- uncommon free scripts

Please login or register to view this content. Registration is FREE
- Städte, Sport, Party, Gourment, Apartments, Hotels
shivaji is offline
Reply With Quote
View Public Profile Visit shivaji's homepage!
 
Old 12-07-2007, 12:54 PM Re: Uploading files from URL and other functions - HELP!
The PHP Professor

Posts: 340
Name: Alex
Location: Behind You
Trades: 0
thanks, but i need to upload through URL not local files.
__________________
Go Kirby! <(" . "<) (^" . "^) (>" . ")> Talkupation!
microcolt is offline
Reply With Quote
View Public Profile Visit microcolt's homepage!
 
Old 12-07-2007, 01:35 PM Re: Uploading files from URL and other functions - HELP!
Joshy D's Avatar
Extreme Talker

Posts: 178
Name: Josh
Trades: 0
Try something lie this:

PHP Code:
<?php
$url 
"http://myurl.com/file.html";
$newlocation "/home/USERNAME/public_html/copiedfiles/";
 
$newfilename "newfile"// what the file will be called in the new location.
$ext 'html'//



if(file_exists($url)) //Check the file exists
{
$filesize file_size($url);

if() 
// Add whatever kind of validation or whatever here
{
if(
copy($url$newlocation.$newfilename.'.'.$ext))
{
echo 
"File Successfully copied from $url to $newlocation";
}
else {
echo 
'Copy failed';
}
}
else {
echo 
'the file size caused a error!';
}
I havent tested it, i think its right...hope it works.
Thanks to Dansgalaxy, yes he's the so called "genius" that wrote this.

Last edited by Joshy D; 12-08-2007 at 12:36 PM..
Joshy D is offline
Reply With Quote
View Public Profile
 
Old 12-07-2007, 05:16 PM Re: Uploading files from URL and other functions - HELP!
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
I would like to point out the above code was written by me... On JoshyD's pc in his bedroom. so if it works could i get the credit please

if it dont work i am happy for josh to look like a idiot
Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 12-08-2007, 12:38 PM Re: Uploading files from URL and other functions - HELP!
Joshy D's Avatar
Extreme Talker

Posts: 178
Name: Josh
Trades: 0
dude you told them that on the end of my post, all i did was change it a little bit to take the mick out of you always calling yourself a genius, i havent taken out the bit that says you wrote it.
Joshy D is offline
Reply With Quote
View Public Profile
 
Old 12-08-2007, 12:40 PM Re: Uploading files from URL and other functions - HELP!
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
haha-ha
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 12-08-2007, 06:26 PM Re: Uploading files from URL and other functions - HELP!
The PHP Professor

Posts: 340
Name: Alex
Location: Behind You
Trades: 0
Thanks for that code, but first the "file_size()" function is "filesize()" and that wont work because it will not work remotely, I think that PHP5 is the only thing that will support the php:// wrappers.

So for anybody else out there i need somthing that can read the file size remotly WITH using PHP4.
__________________
Go Kirby! <(" . "<) (^" . "^) (>" . ")> Talkupation!
microcolt is offline
Reply With Quote
View Public Profile Visit microcolt's homepage!
 
Old 12-08-2007, 07:17 PM Re: Uploading files from URL and other functions - HELP!
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
okay i have found some bits to read the remote file size, but it seems to only be able to do images not .php .txt etc

Does your needs require it to read these files?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 12-08-2007, 08:09 PM Re: Uploading files from URL and other functions - HELP!
The PHP Professor

Posts: 340
Name: Alex
Location: Behind You
Trades: 0
Actually yes, Also i was wondering if some one here could come up with a function that could convert the variable for whatever the URL information is to the $_FILE variable so it could be more compatible with current scripts. I would pay someone to do this if they could do it right!

so like: $file_url_name could be converted to, $_file['name']

and $file_url_size could converted to $_file['size']

I really would pay someone to do this if possible, Thanks!
__________________
Go Kirby! <(" . "<) (^" . "^) (>" . ")> Talkupation!
microcolt is offline
Reply With Quote
View Public Profile Visit microcolt's homepage!
 
Old 12-09-2007, 12:51 PM Re: Uploading files from URL and other functions - HELP!
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
i have to be honest here all this could be done simply like that if it downlaods the file to a temp dir gets all these variables and then if if fails validation or whatever and you dont want it you have the file deleted at the end of the script, this would make it simple and nice and easy.

Email/PM me with all the bits you need for this script and i can probably knock somethin g up

Hope to hear from you soon
Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 12-11-2007, 01:26 AM Re: Uploading files from URL and other functions - HELP!
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
If you want to know the size of remote file before actually downloading it to not download if it is too large, you should use curl extension or exec() curl or wget or whatever and analyze the Content-Length header. If you will download the file anyway, then you may simply download it with curl extension or exec() curl or wget or whatever else and then just treat it like it was uploaded through multipart POST. Nothing will prevent you from doing $_FILES['myfile']['fsize'] = filesize($downloadedFile);
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 12-11-2007, 11:21 AM Re: Uploading files from URL and other functions - HELP!
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
When i was looking it up i came accross a couple of curl bits but didnt really have time to read.
okay got your PM Microcolt but will have to put you on hold for a bit
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 12-11-2007, 01:51 PM Re: Uploading files from URL and other functions - HELP!
Joshy D's Avatar
Extreme Talker

Posts: 178
Name: Josh
Trades: 0
dude, Dan, your an idiot, you dont offer a service then put them on hold, unless you say that you will in your offer, thats just annoying...btw are you ever planning on doing anything for your website or are we going to stop now that i have finished my part?
Joshy D is offline
Reply With Quote
View Public Profile
 
Old 12-11-2007, 04:59 PM Re: Uploading files from URL and other functions - HELP!
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Shut up josh i have only just got back from my meeting and and will be launching the charity site within the next week, thats all.

i was going out so i couldnt provide a free service.

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to Uploading files from URL and other functions - HELP!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.54446 seconds with 12 queries