473,394 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

upload file onto site directory

26
I would like to include a function for speakers to be able to upload presentations onto our website in order to prepare for future talks. Some files can be quite large (e.g. >5-10MB), so my approach was to use ftp to do this.

There is a form where the file can be uploaded and when this is submitted, it is referred to the php ftp script - however, I seem to be getting an error stating:

ftp_login() expects parameter 1 to be resource, boolean given in 'sitepath...'

This is my script:
[PHP]$ftp_server = "serverpath";
$ftp_username = "username";
$ftp_pass = "password";
$connect = ftp_ssl_connect($ftp_server);
$login_result = ftp_login($connect, $ftp_username, $ftp_pass);
$fileupload = addslashes(file_get_contents($_FILES['file']['tmp_name']));
$target = "..Uploads/".$_FILES['userfile']['name']."";
$upload = ftp_put($connect, $target, $fileupload, FTP_BINARY);
ftp_close($connect); [/PHP]

Is there a problem with the script, or is it something to do with permissions on the server?
Aug 29 '07 #1
5 1687
Atli
5,058 Expert 4TB
The problem there is most likely that the ftp_ssl_connect() function is failing, in which case it returns FALSE rather than the resource the ftp_login() function is expecting.

Try validating the connection before you call the ftp_login() function.
Aug 29 '07 #2
Atli
5,058 Expert 4TB
As an afterthought...

Why are you using FTP there?
You have already uploaded the file to the server via the usual HTTP protocol, why not just move it to it's new location using the move_uploaded_file() function?

Unless your moving it to another server?
Aug 29 '07 #3
erp23
26
Well, I tried that way initially, but this is what I've been getting:

Warning: move_uploaded_file(Uploads/a2785.ppt): failed to open stream: Permission denied in 'sitemap' on line 65

Warning: move_uploaded_file(): Unable to move '/tmp/phpHrtNMM' to 'Uploads/a2785.ppt' in 'sitemap' on line 65

This was my initial code:
[PHP]if (file_exists("Uploads/" . $_FILES['file']['name']))
{
echo $_FILES['file']['name'] . " already exists. ";
}
else
{
move_uploaded_file($_FILES['file']['tmp_name'],
"Uploads/" . $_FILES['file']['name']); }[/PHP]

My institution's computer officer is quite cautious on security, and the only way of uploading files is through a secure connetion. What I was wondering is:

1) is it possible to save the file through the browser without ftp (do I need to configure server permissions?)

2)if not, can I get it to work with ftp? I suspect Atli is right, the connect seems to return false - how do I go about fixing that?
Aug 29 '07 #4
Atli
5,058 Expert 4TB
It is indeed possible to save the file without FTP. There is no problem with your script, the only problem is that you, that is to say the PHP script, does not have permission to write to the destination folder.

The best way to make a folder that PHP can write to is to have PHP itself create the folder. That way the user that is running the PHP script is the owner of that folder and has full access to it.

If that is not possible, you will have to give your PHP script, or the user that is running the PHP script, access to your folder. How to do that, will depend on what operating system your server is running on.
Aug 29 '07 #5
erp23
26
How do I make a directory through php?
Would this work?
And would it need to be done every time, or could this be used for multiple uploads?
[PHP]<?php
mkdir("/path", 0777);?>
[/PHP]
Aug 30 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: David | last post by:
Because of limitations of my provider, I am forced to use the ftp functions to upload files to my server (the permissions on the server will not allow me to load files via php). I have...
3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
5
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
1
by: BW | last post by:
I am creating an upload/download function for an extranet site. Files will be uploaded to directory based upon the users login and associated project. The function works as long as I use "c:\Temp"...
18
by: Jen | last post by:
I'm using Microsoft's own VB.NET FTP Example: http://support.microsoft.com/default.aspx?scid=kb;en-us;832679 I can get the program to create directories, change directories, etc., but I can't...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
7
by: pbd22 | last post by:
hi. i am having probs understanding how to grab a file being uploaded from a remote client. i am using hidden input fields for upload such as: <input id="my_file_element" type="file"...
3
acoder
by: acoder | last post by:
How to Upload a File in Coldfusion Use the cffile tag for uploading files to the server. Note that allowing people to upload files is fraught with danger and only trusted users should be...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.