Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

Problem with upload script

Links for php scripts

Moderators: macek, egami, gesf

Problem with upload script

Postby paolofru » Thu May 31, 2012 11:10 am

Hi, I have a big problem with a php script for upload. I have searched many weeks in the web for solve this problem but i haven't find nothing about this...

In my script i have 3 page: invio.php, makedir.php and upload.php

in invio.php i have the form for user data:
Code: Select all
<form id="form1" name="form1" method="post" action="new_makedir.php" enctype="multipart/form-data">
<input type="text" name="azienda" id="azienda2" />


this page submit the variable azienda to makedir.php, this page create a folder on ftp with the name in the variable. I create the session called "azienda" because I need to post this variable to the page upload.php.

Code: Select all
<?php
session_start();

$cartella = $_POST['azienda'];
$login = 'xxx';
$password = 'xxx';

$conn = ftp_connect('xx.xx.xx.xx') or die('Could not connect');
@ftp_login($conn, $login, $password);

$cartella = str_replace(' ', '_', $cartella);
@ftp_mkdir($conn, $cartella);
@ftp_chdir($conn, $cartella);
$_SESSION['cartella'] = $cartella;

?>


In this page i have a flash uploader that called upload.php
Code: Select all
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="544" height="281" id="MultiFileUploader" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="MultiFileUploader.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="MultiFileUploader.swf" quality="high" bgcolor="#ffffff" width="544" height="281" name="MultiFileUploader" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>


the page upload.php take the file and send it to the ftp server
Code: Select all
<?php
<?php
session_start();
print_r($_SESSION);

$cartella_up = $_SESSION['cartella'];

if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $login = 'xyz';
    $password = 'xyz';
   
    $conn = ftp_connect('xx.xx.xx.xx') or die('Could not connect');
    @ftp_login($conn,$login,$password);
    ftp_put($conn, "{$cartella_up}/{$_FILES['Filedata']['name']}", $tempFile, FTP_BINARY);
    ftp_close($conn);
}
?>

and here we have the problem....
the script make the upload of files but only in the root directory, it not recnognize the variable with the name of ftp directory...
but if I specify the name of directory it work perfectly, for example if I change $cartella_up to "test1234" it work perfectly!

have you any idea for the reasonf of this problem.

king regards
paolofru
New php-forum User
New php-forum User
 
Posts: 5
Joined: Thu May 31, 2012 10:53 am

Re: Problem with upload script

Postby Nullsig » Thu May 31, 2012 11:39 am

Is the folder being created and you can't upload the file to it? Or are you not even able to create the file?
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
 
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: Problem with upload script

Postby paolofru » Thu May 31, 2012 12:33 pm

The folder is created without problem but when i try to upload the file is put in the folder root, not in the $_cartella_up folder
paolofru
New php-forum User
New php-forum User
 
Posts: 5
Joined: Thu May 31, 2012 10:53 am

Re: Problem with upload script

Postby Nullsig » Fri Jun 01, 2012 5:02 am

what is the name of the file? Does it maintain the desired name or is it naming it "oddly"?
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
 
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: Problem with upload script

Postby paolofru » Fri Jun 01, 2012 5:43 am

the file maintains the original name, for example if in my HD the name is image.jpg, after the upload in the ftp server it mantains the name image.png.
Also it maintain the original size and if I open this in the server it is perfect.
paolofru
New php-forum User
New php-forum User
 
Posts: 5
Joined: Thu May 31, 2012 10:53 am

Re: Problem with upload script

Postby paolofru » Sat Jun 02, 2012 1:39 am

Nothing else?
paolofru
New php-forum User
New php-forum User
 
Posts: 5
Joined: Thu May 31, 2012 10:53 am

Re: Problem with upload script

Postby paolofru » Sat Jun 02, 2012 12:03 pm

I'VE FOUND THE SOLUTION!!

Code: Select all
<?php
session_start(); //open session

$cartella_up = $_SESSION['cartella']; //session in a string
    $login = 'xyz'; //log ftp
    $password = 'xyz'; //pass ftp
    $conn = ftp_connect('xx.xx.xx.xx') or die('Could not connect'); //ftp connection
    ftp_login($conn,$login,$password); //ftp connection
   $contents = ftp_nlist($conn, "."); //make the folders list

$key = array_search($cartella_up, $contents); //search the key in the array
$cartella_upload = $contents[$key]."/"; //add the slash for path
echo $cartella_upload;  //print for check

if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
  ftp_put($conn, $cartella_upload.$_FILES['Filedata']['name'], $tempFile, FTP_BINARY); //file upload
}
session_destroy(); //close the session
ftp_close($conn);
?>

works, the only problem is that if I go back to the first page and memorize another session I will keep the first ...
I'll try to fix it tomorrow morning ...

YEAH 8) :D
paolofru
New php-forum User
New php-forum User
 
Posts: 5
Joined: Thu May 31, 2012 10:53 am


Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.