Hia guys was wondering if anyone could help me with a php script.
Im working on an idea for an app using pys60 at the moment an im using python to transfer files from my phone to my web server.
Iv finally managed to get the python script to run and post files through a php script onto my server but the problem is that if i upload a file from my phone with the same name as one on the server then it overwrites the previous file on the server and i was wondering if theres a way around this by getting the php script to rename a file if it already exists or even change the file names as they upload?
this is the php script that im using at the moment
<div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'><?php
// Copyright © 2007 LEFEVRE Damien
// image_uploader.php implementation
// In this example a directory "images" needs to be present on the same directory where
// image_uploader.php is, with the necessary rights for the script to write data inside
if(isset($_POST['fileName'])){
$filename = $_POST['fileName'];
}
else{
// if not: just stop here
print "False";
die();
}
if(isset($_POST['data'])){
$encodedData = $_POST['data'];
$data = base64_decode($encodedData);
}
else{
// if not: just stop here
print "False";
die();
}
// full path for the image
$filepathname = 'images/'.$filename;
// write the file to the server into the images directory
$handle = fopen($filepathname, 'wb');
fputs($handle, $data, strlen($data));
fclose($handle);
// return
echo "True";
?></div>
could anyone show me how to fix this or point me towards a couple of examples of how to rename uploads on my server. Iv not really worked with php before so any help would be much appreaciated thanks.
Im working on an idea for an app using pys60 at the moment an im using python to transfer files from my phone to my web server.
Iv finally managed to get the python script to run and post files through a php script onto my server but the problem is that if i upload a file from my phone with the same name as one on the server then it overwrites the previous file on the server and i was wondering if theres a way around this by getting the php script to rename a file if it already exists or even change the file names as they upload?
this is the php script that im using at the moment
<div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'><?php
// Copyright © 2007 LEFEVRE Damien
// image_uploader.php implementation
// In this example a directory "images" needs to be present on the same directory where
// image_uploader.php is, with the necessary rights for the script to write data inside
if(isset($_POST['fileName'])){
$filename = $_POST['fileName'];
}
else{
// if not: just stop here
print "False";
die();
}
if(isset($_POST['data'])){
$encodedData = $_POST['data'];
$data = base64_decode($encodedData);
}
else{
// if not: just stop here
print "False";
die();
}
// full path for the image
$filepathname = 'images/'.$filename;
// write the file to the server into the images directory
$handle = fopen($filepathname, 'wb');
fputs($handle, $data, strlen($data));
fclose($handle);
// return
echo "True";
?></div>
could anyone show me how to fix this or point me towards a couple of examples of how to rename uploads on my server. Iv not really worked with php before so any help would be much appreaciated thanks.