Hi all,
I have a Admin page (only for me, pass required) where I want be able to upload a file from the web, to my website. I want to upload from a URL.
(I can't move_uploaded_f ile() because it's not in the $_FILES array.)
Can anybody please help me out on this?
7 1607
I don't get what I'm supposed to do with file_
get_contents(). ..
Here, say I have a variable containing a file address:
$file = "http://www.host.com/files/image123.jpg";
And I want to upload it to:
$target = "/files/";
How would I use file_get_conten ts() to do that?
Thanks guys, you are very helpful
Atli 5,058
Recognized Expert Expert
You could, for example do: -
<?php
-
$file = "URL to your file";
-
$target = "/path/to/your/save/dir/filename.ext";
-
-
if($contents = file_get_contents($file)) {
-
if(file_put_contents($target, $contents)) {
-
echo "Your file has been uploaded!";
-
}
-
else {
-
echo "Failed to save the file to the target path";
-
}
-
}
-
else {
-
echo "Failed to get the file";
-
}
-
?>
-
Thanks for your post!
It worked. But only when the Target path was set to the entire host directory!
i.e. /home/content/l/i/v/livingsidrah/html/ is considered the root folder (I use godaddy hosting)
Is there any workaround, that I won't need to type the entire directory?
Atli 5,058
Recognized Expert Expert
You should be able to use a relative path. Something like: -
path/to/relative/dir/file.ext
-
Didn't work for me:
PHP file is located here:
ROOT/directory/file.php
Upload target is:
ROOT/directory/files/uploaded_file.e xt
I set $target to /files/uploaded_file.e xt but didn't work.
I had the same problem with file_exists()
Atli 5,058
Recognized Expert Expert
If you use a / in front of a path, a Linux system will assume that is an absolute path, starting from the root directory.
If you want to set a relative path, that is; a path relative to the current directory, do not put a / in front of it.
For example: -
# Lets assume your code is being executed from:
-
# /var/www/html/index.php
-
-
# An absolute path
-
$absolute = "/var/www/html/uploads/newfile.ext";
-
-
# A relative path
-
$relative = "uploads/newfile.ext";
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: dickiedyce |
last post by:
Hi there.
I've spent the weekend getting ever more frustrated, trying to get an
upload file function working on a website.
The site is hosted by a company called oneandone. They're using PHP 4.2.
3, not in safe mode. I think that the basic problem is the set-up for
the temp folder, but I don't have access to the .ini settings.
I'm pretty sure it's possible, because I've got MyPHPAdmin running, and
|
by: R. Rajesh Jeba Anbiah |
last post by:
Q: How should I handle file upload?
A: File uploading requires HTML form of content type
"multipart/form-data". The file content has to be POSTed/submitted via
the form and once the file is uploaded, it will be available at the
"upload_tmp_dir" (usually /tmp) directory. Then you may move that file
to another directory using move_uploaded_file(); file name will be
available in the superglobal $_FILES.
Refer:...
|
by: Kevin Ollivier |
last post by:
Hi all,
I've come across a problem that has me stumped, and I thought I'd send
a message to the gurus to see if this makes sense to anyone else. =)
Basically, I'm trying to upload a series of files via FTP. I'm using
ftplib to do it, and for each file I'm using transfercmd("STOR " +
myfile) to get the socket, then uploading 4096 bytes at a time and
providing status updates via a GUI interface. Finally, I close the
socket, set it to...
|
by: Jonathan |
last post by:
Hi everyone,
I have a problem with the file uploading in Asp.Net and I have read a lot
on forums on this but never found an answer. Here is the problem:
I know Asp.Net maximum Length for uploading a file to the server is 4Mo
but I changed that maximum to about 10Mo in my web.config file :
<httpRuntime executionTimeout="45" maxRequestLength="10000"
useFullyQualifiedRedirectUrl="true" />
|
by: Ron Brennan |
last post by:
Good afternoon.
The entire task that I'm trying to achieve is to allow a user to browse and
upload multiple files simultaneously, hiding the Browse button of <input>
tags of type="file" and replacing it with a button of my own background
color and text.
The file paths I'd like displayed in a textarea and then the files uploaded
at once.
| |
by: Sky Sigal |
last post by:
I have created an IHttpHandler that waits for uploads as attachments for a
webmail interface, and saves it to a directory that is defined in
config.xml.
My question is the following:
assuming that this is suppossed to end up as a component for others to use,
and therefore I do NOT have access to their global.cs::Session_End()
how do I cleanup files that were uploaded -- but obviously left stranded
when the users aborted/gave up writting...
|
by: Jason Chu |
last post by:
I've written a file uploading part of my application using the IHttpModule.
So now, I don't have the memory problem of uploading something big.
Problem:
I can't find which function I have to override, so that I can catch the
event when while user's uploading a file, then suddenly closes the browser.
In that case, couple things happens:
1) ASPNET will start eating up the uploading file on memory instead of on
disk (so picture a...
|
by: Chris |
last post by:
I have a meetings section I'm developing on our intranet. Using PHP/MySQL.
Meeting info and Meeting docs reside on 2 related tables in the db. Users
may want to upload anywhere from 1 to 10 or more documents to share/use
during a meeting presentation. What would be the most efficient way to
approach this? This is the logic I'm currently considering:
Page 1: Meeting Information input with link to a document upload page (this
page...
|
by: wenqiang7 |
last post by:
I am encountering a very strang problem with file uploading in my
ASP.Net page.
When we try to upload certain file, we'll get an error msg of "Cannot
find server or DNS Error".
We are running on Win2003, IIS, ASP.Net 1.1.
The page works fine if running from localhost. It only has problem when
accessed from a domain name.
|
by: ganesanji |
last post by:
hi all,
I have written a php coding for uploading a file to a specific folder or location in
server which is a Linux server. I think the coding for file uploaing is correct.
But it does not work properly. That means the file is not uploaded to the specified location. It always executes the "else" condition in my coding.
I think the problem is lieing in the specifed path which is the target path for file uploading. I could not find out...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |