Jump to content


Photo

Basic File Upload without ftp access


  • Please log in to reply
3 replies to this topic

#1 swatisonee

swatisonee
  • Members
  • PipPipPip
  • Advanced Member
  • 253 posts

Posted 27 April 2006 - 04:31 AM

Hi,

I need to give 5 users only, a way of uploading reports onto our server , which can then be downloaded by us. These will be either word/excel/jpeg files only.

Currently, they email it to us but we need the files to be accessible on the server itself.

Following is the snippet of scripts i use for email. How can i modify so that instead of being in a temp file, it remains permanently there. I dont want to give these users ftp access to the server.

Thanks !
Swati

File1
===


<table> 
<tr><td>Upload a file:</td><td><input name="userfile" type="file">File size should not exceed 2MB</td></tr><p><p>
</table> 
<p> <br><input type="submit" name="submit" value="Submit"> </p> </form>


File2
===

Start of emailing code by posting other info...
if(!($_FILES["userfile"]["name"]=="")) 
{
    $uploaddir="./send_email/";
    //copy the file to some permanent location which has 777 permissions
    
    if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $uploaddir.$_FILES["userfile"]["name"])) 
    {
    echo("<p>File uploaded<p><p>");
    } 
    else 
    {
    echo ("<p>Error in uploading file! Please try again.<br>");
    if($_FILES['userfile']['error']==1) echo "<font color=red>Error: File size exceeds maximum permissible limit of 2MB</font><p><p>";
    }
} 

Rest of emailing code...

File attached: ".$_FILES["userfile"]["name"];

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Emailssent successfully.";

@unlink($attach);
?>

Shishya

#2 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 27 April 2006 - 04:35 AM

Simply rename it?

rename("$_FILES["userfile"]["tmp_name"], "permanent location");

#3 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 27 April 2006 - 04:36 AM

Is there somewhere in the bit of code you have left out where you define $attach as the upload_dir/file_name?

If so, remove the line that deletes the file from the server

@unlink($attach);




If you're not part of the solution, you're part of the precipitate

#4 swatisonee

swatisonee
  • Members
  • PipPipPip
  • Advanced Member
  • 253 posts

Posted 28 April 2006 - 01:37 AM

Hi Sanfly,

The unlink bit is in the code for the php mailer - thats why i didnt copy it. I removed it as you suggested but its not working .

a. When we access the folder on the server, how do we know which files the user has uploaded and their names?

Example: Files on server : a.doc, b.xls, c.jpg.

But i cannot view this list or click on it to download.....

b. Since the file is called tmp_name its creating a problem if 2 users simultaneously try to upload....

Thanks.
Swati
Shishya




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users