Jump to content

$_GET


Schlo_50

Recommended Posts

Hi Guys,

 

Just a quick one. I am trying to pass a string from a text field in a form on one page (a.php) to another page (b.php) via the URL. I have managed to get the string to the other page but cannot get assign it to a variable for use in my upload script. I know the string is getting to b.php as i can print out the string.

 

if(isset($_POST['Submit_a'])){
$ref = $_GET['ref']; 
      $destination_file = "clients/".$ref."/".$myFileName."";
}

 

The problem is that once the upload form is submitted $destination_file doesn't upload the file to clients/$ref/ folder on ftp. Instead it uploads the file to clients/ ignoring $ref.

 

Any ideas?

Link to comment
Share on other sites

clients//doc.jpg

 

where for example it should say clients/folder/doc.jpg

 

b.php

<?php
session_start();

print $_GET['ref'];
$ref = $_GET['ref'];  		
if(isset($_POST['Submit_a'])){
      $myFile = $_FILES['file_ftp']; 
      $file = $myFile['tmp_name'];  
  $max_size = "314572800";     //Max filesize in bytes. (Set to 300MB)

      $myFileName = basename($_POST['fileName']); //Retrieve filename out of file path

      $destination_file = "clients/".$ref."/".$myFileName."";  //webserver path 
  print $destination_file;
      // connection settings
      $ftp_server = "121.5";  //Address of ftp server. (Could also be )
      $ftp_user_name = "user"; // Username
      $ftp_user_pass = "pass";   // Password

      $conn_id = ftp_connect($ftp_server);        // set up connection
      $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("You do not have access to this ftp server!");   
  
      if ((!$conn_id) || (!$login_result)) {  // check connection
           
             print "FTP connection has failed! <br />";
             exit;
         } 
  
  if($_FILES['file_ftp']['size'] > $max_size)
 {
print "Your selected file is too large. You are only permitted to upload files 300MB in size.<br />Your file was <strong>".$_FILES['file_ftp']['size']."</strong> bytes in size.";
 exit;
	  }

      $upload = ftp_put($conn_id, $destination_file, $file, FTP_BINARY);  // upload the file
      if (!$upload) {  // check upload status
         print "Your file upload has been unsuccessful.<br />Failed File: <strong>$myFileName</strong><br />";
      } else {
         print "Your file has uploaded to successfully!<br />Your File: <strong>$myFileName</strong><br />Size: <strong>".$_FILES['file_ftp']['size']."</strong> bytes";
      }

      ftp_close($conn_id); // close
  }
?>

 

Thanks

Link to comment
Share on other sites

NEVER EVER EVER EVER upload a file based entirely on user input.

 

Your best bet is to do something like this

 

call the page like this page.php?ref=3

 

then use

 

$folders = array ('thisfolder', 'thatfolder', 'anotherfolder', 'lastfolder')

if (!is_numeric($_GET['ref']) || $_GET['ref'] > count($folders)-1)

  echo 'Invalid input';

else

  $destination_file = "clients/".$folders[$_GET['ref']]."/".$myFileName."";

 

Imagine if someone called your page like so

 

page.php?ref=../../../some/important/folder/

 

Just not good coding practice.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.