PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hey guys I had some questions last week about using simpleXML to parse XML data. Now I want to do something similiar for image uploads. Basically I want to upload images via a flash uploader (http://www.uploadify.com/) and output file names to an XML file.
Here is what I have so far:
<?php
// JQuery File Upload Plugin v1.4.1 by RonnieSan - (C)2009 Ronnie Garcia
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
// Uncomment the following line if you want to make the directory if it doesn't exist
// mkdir(str_replace('//','/',$targetPath), 0755, true);
move_uploaded_file($tempFile,$targetFile);
}
echo '1';
foreach($_FILES['Filedata']['name'] as $str;)
{
$fp = fopen('upload.xml', 'w');
fwrite($fp, $str);
fclose($fp);
header("Location: http://mydomain.com/imgUpload/");
}
?>
I am trying to create a string for each filename and then write those names directly to an XML file that already exists on the server. Besides any basic permissions problems can anyone see any reason why this wouldn't work?
Last edited by Benjamin on Mon May 18, 2009 10:08 am, edited 1 time in total.
Reason:Changed code type from text to php.
Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
You have to use 'a+' instead. This will create file if it does not exist, or append to it.
<?php
// JQuery File Upload Plugin v1.4.1 by RonnieSan - (C)2009 Ronnie Garcia
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
// Uncomment the following line if you want to make the directory if it doesn't exist
// mkdir(str_replace('//','/',$targetPath), 0755, true);
move_uploaded_file($tempFile,$targetFile);
}
$str = $_FILES['Filedata']['name'];
$fp = fopen('upload.xml', 'a+');
fwrite($fp, $str);
fclose($fp);
?>
Last edited by Benjamin on Wed May 20, 2009 7:53 am, edited 1 time in total.
Reason:Changed code type from text to php.